Skip to content

Commit 9fc2f1a

Browse files
committed
Merge branch 'master' into single-node-discovery
* master: Clear the interrupt flag before joining Migrate to max line length of 100 Docs: Corrected path to elasticsearch-plugin (elastic#23622) Docs: Add comma to reverse nested agg snippet Fix third-party audit task for Gradle 3.4 (elastic#23612) Adapter action future should restore interrupts Update scripting.asciidoc Unmark reindex as experimental CompletionSuggestionContext#toQuery() should also consider text if prefix/regex missing (elastic#23451) Docs: Specify that byte units use powers of 1024 (elastic#23574) Remove Settings.settingsBuilder (elastic#23575) Change params._source to params['_source'] in example. Fix example in documentation for Painless using _source. (elastic#21322) Remove extra line from license header Fix num docs to be positive in bucket deferring collector test Mapping: Fix NPE with scaled floats stats when field is not indexed (elastic#23528)
2 parents 94a79d4 + c462d7d commit 9fc2f1a

File tree

20 files changed

+3538
-204
lines changed

20 files changed

+3538
-204
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/precommit/ThirdPartyAuditTask.groovy

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,11 @@ public class ThirdPartyAuditTask extends AntTask {
209209
try {
210210
ant.thirdPartyAudit(failOnUnsupportedJava: false,
211211
failOnMissingClasses: false,
212-
signaturesFile: new File(getClass().getResource('/forbidden/third-party-audit.txt').toURI()),
213212
classpath: classpath.asPath) {
214213
fileset(dir: tmpDir)
214+
signatures {
215+
string(value: getClass().getResourceAsStream('/forbidden/third-party-audit.txt').getText('UTF-8'))
216+
}
215217
}
216218
} catch (BuildException ignore) {}
217219

buildSrc/src/main/resources/checkstyle.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
suppress the check there but enforce it everywhere else. This prevents the list from getting longer even if it is
2323
unfair. -->
2424
<module name="LineLength">
25-
<property name="max" value="140"/>
25+
<property name="max" value="100"/>
2626
</module>
2727

2828
<module name="AvoidStarImport" />

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 3347 additions & 158 deletions
Large diffs are not rendered by default.

core/src/main/java/org/elasticsearch/action/support/AdapterActionFuture.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public T actionGet() {
3838
try {
3939
return get();
4040
} catch (InterruptedException e) {
41+
Thread.currentThread().interrupt();
4142
throw new IllegalStateException("Future got interrupted", e);
4243
} catch (ExecutionException e) {
4344
throw rethrowExecutionException(e);
@@ -66,6 +67,7 @@ public T actionGet(long timeout, TimeUnit unit) {
6667
} catch (TimeoutException e) {
6768
throw new ElasticsearchTimeoutException(e);
6869
} catch (InterruptedException e) {
70+
Thread.currentThread().interrupt();
6971
throw new IllegalStateException("Future got interrupted", e);
7072
} catch (ExecutionException e) {
7173
throw rethrowExecutionException(e);
@@ -100,4 +102,5 @@ public void onFailure(Exception e) {
100102
}
101103

102104
protected abstract T convert(L listenerResponse);
105+
103106
}

core/src/main/java/org/elasticsearch/index/mapper/ScaledFloatFieldMapper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,16 @@ public FieldStats<?> stats(IndexReader reader) throws IOException {
265265
if (stats == null) {
266266
return null;
267267
}
268-
return new FieldStats.Double(stats.getMaxDoc(), stats.getDocCount(),
268+
if (stats.hasMinMax()) {
269+
return new FieldStats.Double(stats.getMaxDoc(), stats.getDocCount(),
269270
stats.getSumDocFreq(), stats.getSumTotalTermFreq(),
270271
stats.isSearchable(), stats.isAggregatable(),
271-
stats.getMinValue() == null ? null : stats.getMinValue() / scalingFactor,
272-
stats.getMaxValue() == null ? null : stats.getMaxValue() / scalingFactor);
272+
stats.getMinValue() / scalingFactor,
273+
stats.getMaxValue() / scalingFactor);
274+
}
275+
return new FieldStats.Double(stats.getMaxDoc(), stats.getDocCount(),
276+
stats.getSumDocFreq(), stats.getSumTotalTermFreq(),
277+
stats.isSearchable(), stats.isAggregatable());
273278
}
274279

275280
@Override

core/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionContext.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package org.elasticsearch.search.suggest.completion;
2020

2121
import org.apache.lucene.search.suggest.document.CompletionQuery;
22+
import org.apache.lucene.util.BytesRef;
2223
import org.elasticsearch.common.unit.Fuzziness;
2324
import org.elasticsearch.index.mapper.CompletionFieldMapper;
2425
import org.elasticsearch.index.query.QueryShardContext;
@@ -77,15 +78,7 @@ CompletionQuery toQuery() {
7778
CompletionFieldMapper.CompletionFieldType fieldType = getFieldType();
7879
final CompletionQuery query;
7980
if (getPrefix() != null) {
80-
if (fuzzyOptions != null) {
81-
query = fieldType.fuzzyQuery(getPrefix().utf8ToString(),
82-
Fuzziness.fromEdits(fuzzyOptions.getEditDistance()),
83-
fuzzyOptions.getFuzzyPrefixLength(), fuzzyOptions.getFuzzyMinLength(),
84-
fuzzyOptions.getMaxDeterminizedStates(), fuzzyOptions.isTranspositions(),
85-
fuzzyOptions.isUnicodeAware());
86-
} else {
87-
query = fieldType.prefixQuery(getPrefix());
88-
}
81+
query = createCompletionQuery(getPrefix(), fieldType);
8982
} else if (getRegex() != null) {
9083
if (fuzzyOptions != null) {
9184
throw new IllegalArgumentException("can not use 'fuzzy' options with 'regex");
@@ -95,8 +88,10 @@ CompletionQuery toQuery() {
9588
}
9689
query = fieldType.regexpQuery(getRegex(), regexOptions.getFlagsValue(),
9790
regexOptions.getMaxDeterminizedStates());
91+
} else if (getText() != null) {
92+
query = createCompletionQuery(getText(), fieldType);
9893
} else {
99-
throw new IllegalArgumentException("'prefix' or 'regex' must be defined");
94+
throw new IllegalArgumentException("'prefix/text' or 'regex' must be defined");
10095
}
10196
if (fieldType.hasContextMappings()) {
10297
ContextMappings contextMappings = fieldType.getContextMappings();
@@ -105,4 +100,18 @@ CompletionQuery toQuery() {
105100
return query;
106101
}
107102

103+
private CompletionQuery createCompletionQuery(BytesRef prefix, CompletionFieldMapper.CompletionFieldType fieldType) {
104+
final CompletionQuery query;
105+
if (fuzzyOptions != null) {
106+
query = fieldType.fuzzyQuery(prefix.utf8ToString(),
107+
Fuzziness.fromEdits(fuzzyOptions.getEditDistance()),
108+
fuzzyOptions.getFuzzyPrefixLength(), fuzzyOptions.getFuzzyMinLength(),
109+
fuzzyOptions.getMaxDeterminizedStates(), fuzzyOptions.isTranspositions(),
110+
fuzzyOptions.isUnicodeAware());
111+
} else {
112+
query = fieldType.prefixQuery(prefix);
113+
}
114+
return query;
115+
}
116+
108117
}
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.elasticsearch.action.support;
21+
22+
import org.elasticsearch.common.unit.TimeValue;
23+
import org.elasticsearch.test.ESTestCase;
24+
25+
import java.util.Objects;
26+
import java.util.concurrent.BrokenBarrierException;
27+
import java.util.concurrent.CyclicBarrier;
28+
import java.util.concurrent.TimeUnit;
29+
import java.util.concurrent.atomic.AtomicBoolean;
30+
31+
public class AdapterActionFutureTests extends ESTestCase {
32+
33+
public void testInterruption() throws Exception {
34+
final AdapterActionFuture<String, Integer> adapter =
35+
new AdapterActionFuture<String, Integer>() {
36+
@Override
37+
protected String convert(final Integer listenerResponse) {
38+
return Objects.toString(listenerResponse);
39+
}
40+
};
41+
42+
// test all possible methods that can be interrupted
43+
final Runnable runnable = () -> {
44+
final int method = randomIntBetween(0, 4);
45+
switch (method) {
46+
case 0:
47+
adapter.actionGet();
48+
break;
49+
case 1:
50+
adapter.actionGet("30s");
51+
break;
52+
case 2:
53+
adapter.actionGet(30000);
54+
break;
55+
case 3:
56+
adapter.actionGet(TimeValue.timeValueSeconds(30));
57+
break;
58+
case 4:
59+
adapter.actionGet(30, TimeUnit.SECONDS);
60+
break;
61+
default:
62+
throw new AssertionError(method);
63+
}
64+
};
65+
66+
final CyclicBarrier barrier = new CyclicBarrier(2);
67+
final Thread main = Thread.currentThread();
68+
final Thread thread = new Thread(() -> {
69+
try {
70+
barrier.await();
71+
} catch (final BrokenBarrierException | InterruptedException e) {
72+
throw new RuntimeException(e);
73+
}
74+
main.interrupt();
75+
});
76+
thread.start();
77+
78+
final AtomicBoolean interrupted = new AtomicBoolean();
79+
80+
barrier.await();
81+
82+
try {
83+
runnable.run();
84+
} catch (final IllegalStateException e) {
85+
interrupted.set(Thread.interrupted());
86+
}
87+
// we check this here instead of in the catch block to ensure that the catch block executed
88+
assertTrue(interrupted.get());
89+
90+
thread.join();
91+
}
92+
93+
}

core/src/test/java/org/elasticsearch/index/mapper/ScaledFloatFieldTypeTests.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import org.apache.lucene.document.DoublePoint;
2424
import org.apache.lucene.document.LongPoint;
2525
import org.apache.lucene.document.SortedNumericDocValuesField;
26+
import org.apache.lucene.document.StoredField;
2627
import org.apache.lucene.index.DirectoryReader;
2728
import org.apache.lucene.index.IndexWriter;
2829
import org.apache.lucene.index.IndexWriterConfig;
@@ -143,6 +144,15 @@ public void testStats() throws IOException {
143144
assertNull(ft.stats(reader));
144145
}
145146
Document doc = new Document();
147+
doc.add(new StoredField("scaled_float", -1));
148+
w.addDocument(doc);
149+
try (DirectoryReader reader = DirectoryReader.open(w)) {
150+
// field exists, but has no point values
151+
FieldStats<?> stats = ft.stats(reader);
152+
assertFalse(stats.hasMinMax());
153+
assertNull(stats.getMinValue());
154+
assertNull(stats.getMaxValue());
155+
}
146156
LongPoint point = new LongPoint("scaled_float", -1);
147157
doc.add(point);
148158
w.addDocument(doc);
@@ -152,7 +162,7 @@ public void testStats() throws IOException {
152162
FieldStats<?> stats = ft.stats(reader);
153163
assertEquals(-1/ft.getScalingFactor(), stats.getMinValue());
154164
assertEquals(10/ft.getScalingFactor(), stats.getMaxValue());
155-
assertEquals(2, stats.getMaxDoc());
165+
assertEquals(3, stats.getMaxDoc());
156166
}
157167
w.deleteAll();
158168
try (DirectoryReader reader = DirectoryReader.open(w)) {

core/src/test/java/org/elasticsearch/search/aggregations/bucket/BestBucketsDeferringCollectorTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public class BestBucketsDeferringCollectorTests extends AggregatorTestCase {
4646
public void testReplay() throws Exception {
4747
Directory directory = newDirectory();
4848
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
49-
int numDocs = randomInt(128);
49+
int numDocs = randomIntBetween(1, 128);
5050
int maxNumValues = randomInt(16);
5151
for (int i = 0; i < numDocs; i++) {
5252
Document document = new Document();

core/src/test/java/org/elasticsearch/search/suggest/CompletionSuggestSearchIT.java

Lines changed: 33 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,10 @@
6868
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
6969
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
7070
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAllSuccessful;
71-
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures;
7271
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchHit;
7372
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasId;
7473
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.hasScore;
7574
import static org.hamcrest.Matchers.contains;
76-
import static org.hamcrest.Matchers.containsInAnyOrder;
7775
import static org.hamcrest.Matchers.containsString;
7876
import static org.hamcrest.Matchers.equalTo;
7977
import static org.hamcrest.Matchers.greaterThan;
@@ -116,6 +114,36 @@ public void testPrefix() throws Exception {
116114
assertSuggestions("foo", prefix, "suggestion10", "suggestion9", "suggestion8", "suggestion7", "suggestion6");
117115
}
118116

117+
/**
118+
* test that suggestion works if prefix is either provided via {@link CompletionSuggestionBuilder#text(String)} or
119+
* {@link SuggestBuilder#setGlobalText(String)}
120+
*/
121+
public void testTextAndGlobalText() throws Exception {
122+
final CompletionMappingBuilder mapping = new CompletionMappingBuilder();
123+
createIndexAndMapping(mapping);
124+
int numDocs = 10;
125+
List<IndexRequestBuilder> indexRequestBuilders = new ArrayList<>();
126+
for (int i = 1; i <= numDocs; i++) {
127+
indexRequestBuilders.add(client().prepareIndex(INDEX, TYPE, "" + i).setSource(jsonBuilder().startObject().startObject(FIELD)
128+
.field("input", "suggestion" + i).field("weight", i).endObject().endObject()));
129+
}
130+
indexRandom(true, indexRequestBuilders);
131+
CompletionSuggestionBuilder noText = SuggestBuilders.completionSuggestion(FIELD);
132+
SearchResponse searchResponse = client().prepareSearch(INDEX)
133+
.suggest(new SuggestBuilder().addSuggestion("foo", noText).setGlobalText("sugg")).execute().actionGet();
134+
assertSuggestions(searchResponse, "foo", "suggestion10", "suggestion9", "suggestion8", "suggestion7", "suggestion6");
135+
136+
CompletionSuggestionBuilder withText = SuggestBuilders.completionSuggestion(FIELD).text("sugg");
137+
searchResponse = client().prepareSearch(INDEX)
138+
.suggest(new SuggestBuilder().addSuggestion("foo", withText)).execute().actionGet();
139+
assertSuggestions(searchResponse, "foo", "suggestion10", "suggestion9", "suggestion8", "suggestion7", "suggestion6");
140+
141+
// test that suggestion text takes precedence over global text
142+
searchResponse = client().prepareSearch(INDEX)
143+
.suggest(new SuggestBuilder().addSuggestion("foo", withText).setGlobalText("bogus")).execute().actionGet();
144+
assertSuggestions(searchResponse, "foo", "suggestion10", "suggestion9", "suggestion8", "suggestion7", "suggestion6");
145+
}
146+
119147
public void testRegex() throws Exception {
120148
final CompletionMappingBuilder mapping = new CompletionMappingBuilder();
121149
createIndexAndMapping(mapping);
@@ -217,7 +245,7 @@ public void testSuggestDocument() throws Exception {
217245
for (CompletionSuggestion.Entry.Option option : options) {
218246
assertThat(option.getText().toString(), equalTo("suggestion" + id));
219247
assertSearchHit(option.getHit(), hasId("" + id));
220-
assertSearchHit(option.getHit(), hasScore(((float) id)));
248+
assertSearchHit(option.getHit(), hasScore((id)));
221249
assertNotNull(option.getHit().getSourceAsMap());
222250
id--;
223251
}
@@ -252,7 +280,7 @@ public void testSuggestDocumentNoSource() throws Exception {
252280
for (CompletionSuggestion.Entry.Option option : options) {
253281
assertThat(option.getText().toString(), equalTo("suggestion" + id));
254282
assertSearchHit(option.getHit(), hasId("" + id));
255-
assertSearchHit(option.getHit(), hasScore(((float) id)));
283+
assertSearchHit(option.getHit(), hasScore((id)));
256284
assertNull(option.getHit().getSourceAsMap());
257285
id--;
258286
}
@@ -289,7 +317,7 @@ public void testSuggestDocumentSourceFiltering() throws Exception {
289317
for (CompletionSuggestion.Entry.Option option : options) {
290318
assertThat(option.getText().toString(), equalTo("suggestion" + id));
291319
assertSearchHit(option.getHit(), hasId("" + id));
292-
assertSearchHit(option.getHit(), hasScore(((float) id)));
320+
assertSearchHit(option.getHit(), hasScore((id)));
293321
assertNotNull(option.getHit().getSourceAsMap());
294322
Set<String> sourceFields = option.getHit().getSourceAsMap().keySet();
295323
assertThat(sourceFields, contains("a"));

0 commit comments

Comments
 (0)