Skip to content

Commit 3d91e31

Browse files
committed
Merge branch 'master' into java-time
2 parents 972e5a4 + 433a506 commit 3d91e31

File tree

41 files changed

+281
-415
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+281
-415
lines changed

docs/reference/migration/migrate_7_0/search.asciidoc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,3 +159,14 @@ Negative scores in the Function Score Query are deprecated in 6.x, and are
159159
not allowed in this version. If a negative score is produced as a result
160160
of computation (e.g. in `script_score` or `field_value_factor` functions),
161161
an error will be thrown.
162+
163+
[float]
164+
==== The filter context has been removed
165+
166+
The `filter` context has been removed from Elasticsearch's query builders,
167+
the distinction between queries and filters is now decided in Lucene depending
168+
on whether queries need to access score or not. As a result `bool` queries with
169+
`should` clauses that don't need to access the score will no longer set their
170+
`minimum_should_match` to 1. This behavior has been deprecated in the previous
171+
major version.
172+

docs/reference/query-dsl/bool-query.asciidoc

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,14 @@ contribute to the score.
1717
in <<query-filter-context,filter context>>, meaning that scoring is ignored
1818
and clauses are considered for caching.
1919

20-
|`should` |The clause (query) should appear in the matching document. If the
21-
`bool` query is in a <<query-filter-context,query context>> and has a `must` or
22-
`filter` clause then a document will match the `bool` query even if none of the
23-
`should` queries match. In this case these clauses are only used to influence
24-
the score. If the `bool` query is a <<query-filter-context,filter context>>
25-
or has neither `must` or `filter` then at least one of the `should` queries
26-
must match a document for it to match the `bool` query. This behavior may be
27-
explicitly controlled by settings the
28-
<<query-dsl-minimum-should-match,`minimum_should_match`>> parameter.
20+
|`should` |The clause (query) should appear in the matching document.
2921

3022
|`must_not` |The clause (query) must not appear in the matching
3123
documents. Clauses are executed in <<query-filter-context,filter context>> meaning
3224
that scoring is ignored and clauses are considered for caching. Because scoring is
3325
ignored, a score of `0` for all documents is returned.
3426
|=======================================================================
3527

36-
[IMPORTANT]
37-
.Bool query in filter context
38-
========================================================================
39-
If this query is used in a filter context and it has `should`
40-
clauses then at least one `should` clause is required to match.
41-
========================================================================
42-
4328
The `bool` query takes a _more-matches-is-better_ approach, so the score from
4429
each matching `must` or `should` clause will be added together to provide the
4530
final `_score` for each document.

server/src/main/java/org/elasticsearch/cluster/metadata/AliasValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,6 @@ public void validateAliasFilter(String alias, byte[] filter, QueryShardContext q
139139
private static void validateAliasFilter(XContentParser parser, QueryShardContext queryShardContext) throws IOException {
140140
QueryBuilder parseInnerQueryBuilder = parseInnerQueryBuilder(parser);
141141
QueryBuilder queryBuilder = Rewriteable.rewrite(parseInnerQueryBuilder, queryShardContext, true);
142-
queryBuilder.toFilter(queryShardContext);
142+
queryBuilder.toQuery(queryShardContext);
143143
}
144144
}

server/src/main/java/org/elasticsearch/index/query/AbstractQueryBuilder.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,19 +111,6 @@ public final Query toQuery(QueryShardContext context) throws IOException {
111111
return query;
112112
}
113113

114-
@Override
115-
public final Query toFilter(QueryShardContext context) throws IOException {
116-
Query result;
117-
final boolean originalIsFilter = context.isFilter();
118-
try {
119-
context.setIsFilter(true);
120-
result = toQuery(context);
121-
} finally {
122-
context.setIsFilter(originalIsFilter);
123-
}
124-
return result;
125-
}
126-
127114
protected abstract Query doToQuery(QueryShardContext context) throws IOException;
128115

129116
/**

server/src/main/java/org/elasticsearch/index/query/BoolQueryBuilder.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -384,30 +384,14 @@ protected Query doToQuery(QueryShardContext context) throws IOException {
384384
return new MatchAllDocsQuery();
385385
}
386386

387-
final String minimumShouldMatch;
388-
if (context.isFilter() && this.minimumShouldMatch == null && shouldClauses.size() > 0) {
389-
minimumShouldMatch = "1";
390-
} else {
391-
minimumShouldMatch = this.minimumShouldMatch;
392-
}
393387
Query query = Queries.applyMinimumShouldMatch(booleanQuery, minimumShouldMatch);
394388
return adjustPureNegative ? fixNegativeQueryIfNeeded(query) : query;
395389
}
396390

397391
private static void addBooleanClauses(QueryShardContext context, BooleanQuery.Builder booleanQueryBuilder,
398392
List<QueryBuilder> clauses, Occur occurs) throws IOException {
399393
for (QueryBuilder query : clauses) {
400-
Query luceneQuery = null;
401-
switch (occurs) {
402-
case MUST:
403-
case SHOULD:
404-
luceneQuery = query.toQuery(context);
405-
break;
406-
case FILTER:
407-
case MUST_NOT:
408-
luceneQuery = query.toFilter(context);
409-
break;
410-
}
394+
Query luceneQuery = query.toQuery(context);
411395
booleanQueryBuilder.add(new BooleanClause(luceneQuery, occurs));
412396
}
413397
}

server/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public static ConstantScoreQueryBuilder fromXContent(XContentParser parser) thro
129129

130130
@Override
131131
protected Query doToQuery(QueryShardContext context) throws IOException {
132-
Query innerFilter = filterBuilder.toFilter(context);
132+
Query innerFilter = filterBuilder.toQuery(context);
133133
return new ConstantScoreQuery(innerFilter);
134134
}
135135

server/src/main/java/org/elasticsearch/index/query/FuzzyQueryBuilder.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,9 +326,6 @@ public String getWriteableName() {
326326
protected Query doToQuery(QueryShardContext context) throws IOException {
327327
Query query = null;
328328
String rewrite = this.rewrite;
329-
if (rewrite == null && context.isFilter()) {
330-
rewrite = QueryParsers.CONSTANT_SCORE.getPreferredName();
331-
}
332329
MappedFieldType fieldType = context.fieldMapper(fieldName);
333330
if (fieldType != null) {
334331
query = fieldType.fuzzyQuery(value, fuzziness, prefixLength, maxExpansions, transpositions);

server/src/main/java/org/elasticsearch/index/query/QueryBuilder.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,6 @@ public interface QueryBuilder extends NamedWriteable, ToXContentObject, Rewritea
3737
*/
3838
Query toQuery(QueryShardContext context) throws IOException;
3939

40-
/**
41-
* Converts this QueryBuilder to an unscored lucene {@link Query} that acts as a filter.
42-
* Returns {@code null} if this query should be ignored in the context of
43-
* parent queries.
44-
*
45-
* @param context additional information needed to construct the queries
46-
* @return the {@link Query} or {@code null} if this query should be ignored upstream
47-
*/
48-
Query toFilter(QueryShardContext context) throws IOException;
49-
5040
/**
5141
* Sets the arbitrary name to be assigned to the query (see named queries).
5242
* Implementers should return the concrete type of the

server/src/main/java/org/elasticsearch/index/query/QueryShardContext.java

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ public String[] getTypes() {
9797
private boolean allowUnmappedFields;
9898
private boolean mapUnmappedFieldAsString;
9999
private NestedScope nestedScope;
100-
private boolean isFilter;
101100

102101
public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache,
103102
BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService,
@@ -132,7 +131,6 @@ private void reset() {
132131
this.lookup = null;
133132
this.namedQueries.clear();
134133
this.nestedScope = new NestedScope();
135-
this.isFilter = false;
136134
}
137135

138136
public IndexAnalyzers getIndexAnalyzers() {
@@ -178,22 +176,6 @@ public Map<String, Query> copyNamedQueries() {
178176
return unmodifiableMap(new HashMap<>(namedQueries));
179177
}
180178

181-
/**
182-
* Return whether we are currently parsing a filter or a query.
183-
*/
184-
public boolean isFilter() {
185-
return isFilter;
186-
}
187-
188-
/**
189-
* Public for testing only!
190-
*
191-
* Sets whether we are currently parsing a filter or a query
192-
*/
193-
public void setIsFilter(boolean isFilter) {
194-
this.isFilter = isFilter;
195-
}
196-
197179
/**
198180
* Returns all the fields that match a given pattern. If prefixed with a
199181
* type then the fields will be returned with a type prefix.
@@ -289,16 +271,6 @@ public Version indexVersionCreated() {
289271
return indexSettings.getIndexVersionCreated();
290272
}
291273

292-
public ParsedQuery toFilter(QueryBuilder queryBuilder) {
293-
return toQuery(queryBuilder, q -> {
294-
Query filter = q.toFilter(this);
295-
if (filter == null) {
296-
return null;
297-
}
298-
return filter;
299-
});
300-
}
301-
302274
public ParsedQuery toQuery(QueryBuilder queryBuilder) {
303275
return toQuery(queryBuilder, q -> {
304276
Query query = q.toQuery(this);

server/src/main/java/org/elasticsearch/index/query/SpanNearQueryBuilder.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,6 @@ public Query toQuery(QueryShardContext context) throws IOException {
346346
throw new UnsupportedOperationException();
347347
}
348348

349-
@Override
350-
public Query toFilter(QueryShardContext context) throws IOException {
351-
throw new UnsupportedOperationException();
352-
}
353-
354349
@Override
355350
public String queryName() {
356351
throw new UnsupportedOperationException();

server/src/main/java/org/elasticsearch/index/store/Store.java

Lines changed: 13 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@
9191
import java.nio.file.Path;
9292
import java.util.ArrayList;
9393
import java.util.Collections;
94-
import java.util.Comparator;
9594
import java.util.HashMap;
9695
import java.util.Iterator;
9796
import java.util.List;
@@ -300,21 +299,18 @@ public MetadataSnapshot getMetadata(IndexCommit commit, boolean lockDirectory) t
300299
public void renameTempFilesSafe(Map<String, String> tempFileMap) throws IOException {
301300
// this works just like a lucene commit - we rename all temp files and once we successfully
302301
// renamed all the segments we rename the commit to ensure we don't leave half baked commits behind.
303-
final Map.Entry<String, String>[] entries = tempFileMap.entrySet().toArray(new Map.Entry[tempFileMap.size()]);
304-
ArrayUtil.timSort(entries, new Comparator<Map.Entry<String, String>>() {
305-
@Override
306-
public int compare(Map.Entry<String, String> o1, Map.Entry<String, String> o2) {
307-
String left = o1.getValue();
308-
String right = o2.getValue();
309-
if (left.startsWith(IndexFileNames.SEGMENTS) || right.startsWith(IndexFileNames.SEGMENTS)) {
310-
if (left.startsWith(IndexFileNames.SEGMENTS) == false) {
311-
return -1;
312-
} else if (right.startsWith(IndexFileNames.SEGMENTS) == false) {
313-
return 1;
314-
}
302+
final Map.Entry<String, String>[] entries = tempFileMap.entrySet().toArray(new Map.Entry[0]);
303+
ArrayUtil.timSort(entries, (o1, o2) -> {
304+
String left = o1.getValue();
305+
String right = o2.getValue();
306+
if (left.startsWith(IndexFileNames.SEGMENTS) || right.startsWith(IndexFileNames.SEGMENTS)) {
307+
if (left.startsWith(IndexFileNames.SEGMENTS) == false) {
308+
return -1;
309+
} else if (right.startsWith(IndexFileNames.SEGMENTS) == false) {
310+
return 1;
315311
}
316-
return left.compareTo(right);
317312
}
313+
return left.compareTo(right);
318314
});
319315
metadataLock.writeLock().lock();
320316
// we make sure that nobody fetches the metadata while we do this rename operation here to ensure we don't
@@ -454,22 +450,6 @@ public static MetadataSnapshot readMetadataSnapshot(Path indexLocation, ShardId
454450
return MetadataSnapshot.EMPTY;
455451
}
456452

457-
/**
458-
* Returns <code>true</code> iff the given location contains an index an the index
459-
* can be successfully opened. This includes reading the segment infos and possible
460-
* corruption markers.
461-
*/
462-
public static boolean canOpenIndex(Logger logger, Path indexLocation,
463-
ShardId shardId, NodeEnvironment.ShardLocker shardLocker) throws IOException {
464-
try {
465-
tryOpenIndex(indexLocation, shardId, shardLocker, logger);
466-
} catch (Exception ex) {
467-
logger.trace(() -> new ParameterizedMessage("Can't open index for path [{}]", indexLocation), ex);
468-
return false;
469-
}
470-
return true;
471-
}
472-
473453
/**
474454
* Tries to open an index for the given location. This includes reading the
475455
* segment infos and possible corruption markers. If the index can not
@@ -961,7 +941,6 @@ public Map<String, StoreFileMetaData> asMap() {
961941

962942
private static final String DEL_FILE_EXTENSION = "del"; // legacy delete file
963943
private static final String LIV_FILE_EXTENSION = "liv"; // lucene 5 delete file
964-
private static final String FIELD_INFOS_FILE_EXTENSION = "fnm";
965944
private static final String SEGMENT_INFO_EXTENSION = "si";
966945

967946
/**
@@ -1015,12 +994,7 @@ public RecoveryDiff recoveryDiff(MetadataSnapshot recoveryTargetSnapshot) {
1015994
// only treat del files as per-commit files fnm files are generational but only for upgradable DV
1016995
perCommitStoreFiles.add(meta);
1017996
} else {
1018-
List<StoreFileMetaData> perSegStoreFiles = perSegment.get(segmentId);
1019-
if (perSegStoreFiles == null) {
1020-
perSegStoreFiles = new ArrayList<>();
1021-
perSegment.put(segmentId, perSegStoreFiles);
1022-
}
1023-
perSegStoreFiles.add(meta);
997+
perSegment.computeIfAbsent(segmentId, k -> new ArrayList<>()).add(meta);
1024998
}
1025999
}
10261000
final ArrayList<StoreFileMetaData> identicalFiles = new ArrayList<>();
@@ -1072,13 +1046,6 @@ public String getHistoryUUID() {
10721046
return commitUserData.get(Engine.HISTORY_UUID_KEY);
10731047
}
10741048

1075-
/**
1076-
* returns the translog uuid the store points at
1077-
*/
1078-
public String getTranslogUUID() {
1079-
return commitUserData.get(Translog.TRANSLOG_UUID_KEY);
1080-
}
1081-
10821049
/**
10831050
* Returns true iff this metadata contains the given file.
10841051
*/
@@ -1598,15 +1565,14 @@ public void trimUnsafeCommits(final long lastSyncedGlobalCheckpoint, final long
15981565
}
15991566
}
16001567

1601-
1602-
private void updateCommitData(IndexWriter writer, Map<String, String> keysToUpdate) throws IOException {
1568+
private static void updateCommitData(IndexWriter writer, Map<String, String> keysToUpdate) throws IOException {
16031569
final Map<String, String> userData = getUserData(writer);
16041570
userData.putAll(keysToUpdate);
16051571
writer.setLiveCommitData(userData.entrySet());
16061572
writer.commit();
16071573
}
16081574

1609-
private Map<String, String> getUserData(IndexWriter writer) {
1575+
private static Map<String, String> getUserData(IndexWriter writer) {
16101576
final Map<String, String> userData = new HashMap<>();
16111577
writer.getLiveCommitData().forEach(e -> userData.put(e.getKey(), e.getValue()));
16121578
return userData;

0 commit comments

Comments
 (0)