Wire query cache into sorting nested-filter computation (#42906)

Don't use Lucene's default query cache when filtering in sort.

Closes #42813
This commit is contained in:
henryptung 2019-06-06 11:21:16 -07:00 committed by jimczi
parent d18f511327
commit 61b62125b8
22 changed files with 77 additions and 49 deletions

View File

@ -21,6 +21,8 @@ package org.elasticsearch.index;
import org.apache.logging.log4j.message.ParameterizedMessage; import org.apache.logging.log4j.message.ParameterizedMessage;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Sort; import org.apache.lucene.search.Sort;
import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
@ -518,6 +520,13 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
return indexSettings; return indexSettings;
} }
private IndexSearcher newCachedSearcher(int shardId, IndexReaderContext context) {
IndexSearcher searcher = new IndexSearcher(context);
searcher.setQueryCache(cache().query());
searcher.setQueryCachingPolicy(getShard(shardId).getQueryCachingPolicy());
return searcher;
}
/** /**
* Creates a new QueryShardContext. The context has not types set yet, if types are required set them via * Creates a new QueryShardContext. The context has not types set yet, if types are required set them via
* {@link QueryShardContext#setTypes(String...)}. * {@link QueryShardContext#setTypes(String...)}.
@ -527,10 +536,9 @@ public class IndexService extends AbstractIndexComponent implements IndicesClust
*/ */
public QueryShardContext newQueryShardContext(int shardId, IndexReader indexReader, LongSupplier nowInMillis, String clusterAlias) { public QueryShardContext newQueryShardContext(int shardId, IndexReader indexReader, LongSupplier nowInMillis, String clusterAlias) {
return new QueryShardContext( return new QueryShardContext(
shardId, indexSettings, indexCache.bitsetFilterCache(), indexFieldData::getForField, mapperService(), shardId, indexSettings, indexCache.bitsetFilterCache(), context -> newCachedSearcher(shardId, context),
similarityService(), scriptService, xContentRegistry, indexFieldData::getForField, mapperService(), similarityService(), scriptService, xContentRegistry, namedWriteableRegistry,
namedWriteableRegistry, client, indexReader, client, indexReader, nowInMillis, clusterAlias);
nowInMillis, clusterAlias);
} }
/** /**

View File

@ -47,6 +47,7 @@ import org.elasticsearch.search.MultiValueMode;
import org.elasticsearch.search.sort.NestedSortBuilder; import org.elasticsearch.search.sort.NestedSortBuilder;
import java.io.IOException; import java.io.IOException;
import java.util.function.Function;
/** /**
* Thread-safe utility class that allows to get per-segment values via the * Thread-safe utility class that allows to get per-segment values via the
@ -114,11 +115,14 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
private final BitSetProducer rootFilter; private final BitSetProducer rootFilter;
private final Query innerQuery; private final Query innerQuery;
private final NestedSortBuilder nestedSort; private final NestedSortBuilder nestedSort;
private final Function<IndexReaderContext, IndexSearcher> searcherFactory;
public Nested(BitSetProducer rootFilter, Query innerQuery, NestedSortBuilder nestedSort) { public Nested(BitSetProducer rootFilter, Query innerQuery, NestedSortBuilder nestedSort,
Function<IndexReaderContext, IndexSearcher> searcherFactory) {
this.rootFilter = rootFilter; this.rootFilter = rootFilter;
this.innerQuery = innerQuery; this.innerQuery = innerQuery;
this.nestedSort = nestedSort; this.nestedSort = nestedSort;
this.searcherFactory = searcherFactory;
} }
public Query getInnerQuery() { public Query getInnerQuery() {
@ -143,7 +147,7 @@ public interface IndexFieldData<FD extends AtomicFieldData> extends IndexCompone
*/ */
public DocIdSetIterator innerDocs(LeafReaderContext ctx) throws IOException { public DocIdSetIterator innerDocs(LeafReaderContext ctx) throws IOException {
final IndexReaderContext topLevelCtx = ReaderUtil.getTopLevelContext(ctx); final IndexReaderContext topLevelCtx = ReaderUtil.getTopLevelContext(ctx);
IndexSearcher indexSearcher = new IndexSearcher(topLevelCtx); IndexSearcher indexSearcher = searcherFactory.apply(topLevelCtx);
Weight weight = indexSearcher.createWeight(indexSearcher.rewrite(innerQuery), ScoreMode.COMPLETE_NO_SCORES, 1f); Weight weight = indexSearcher.createWeight(indexSearcher.rewrite(innerQuery), ScoreMode.COMPLETE_NO_SCORES, 1f);
Scorer s = weight.scorer(ctx); Scorer s = weight.scorer(ctx);
return s == null ? null : s.iterator(); return s == null ? null : s.iterator();

View File

@ -22,6 +22,8 @@ package org.elasticsearch.index.query;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexReaderContext;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query; import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.BitSetProducer; import org.apache.lucene.search.join.BitSetProducer;
import org.apache.lucene.search.similarities.Similarity; import org.apache.lucene.search.similarities.Similarity;
@ -65,6 +67,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
import java.util.function.BiFunction; import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.LongSupplier; import java.util.function.LongSupplier;
import static java.util.Collections.unmodifiableMap; import static java.util.Collections.unmodifiableMap;
@ -83,6 +86,7 @@ public class QueryShardContext extends QueryRewriteContext {
private final MapperService mapperService; private final MapperService mapperService;
private final SimilarityService similarityService; private final SimilarityService similarityService;
private final BitsetFilterCache bitsetFilterCache; private final BitsetFilterCache bitsetFilterCache;
private final Function<IndexReaderContext, IndexSearcher> searcherFactory;
private final BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataService; private final BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataService;
private final int shardId; private final int shardId;
private final IndexReader reader; private final IndexReader reader;
@ -105,23 +109,25 @@ public class QueryShardContext extends QueryRewriteContext {
private NestedScope nestedScope; private NestedScope nestedScope;
public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache, public QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache,
Function<IndexReaderContext, IndexSearcher> searcherFactory,
BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService, BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService,
SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry,
NamedWriteableRegistry namedWriteableRegistry, Client client, IndexReader reader, LongSupplier nowInMillis, NamedWriteableRegistry namedWriteableRegistry, Client client, IndexReader reader, LongSupplier nowInMillis,
String clusterAlias) { String clusterAlias) {
this(shardId, indexSettings, bitsetFilterCache, indexFieldDataLookup, mapperService, similarityService, scriptService, this(shardId, indexSettings, bitsetFilterCache, searcherFactory, indexFieldDataLookup, mapperService, similarityService,
xContentRegistry, namedWriteableRegistry, client, reader, nowInMillis, new Index(RemoteClusterAware.buildRemoteIndexName( scriptService, xContentRegistry, namedWriteableRegistry, client, reader, nowInMillis,
clusterAlias, indexSettings.getIndex().getName()), indexSettings.getIndex().getUUID())); new Index(RemoteClusterAware.buildRemoteIndexName(clusterAlias, indexSettings.getIndex().getName()),
indexSettings.getIndex().getUUID()));
} }
public QueryShardContext(QueryShardContext source) { public QueryShardContext(QueryShardContext source) {
this(source.shardId, source.indexSettings, source.bitsetFilterCache, source.indexFieldDataService, source.mapperService, this(source.shardId, source.indexSettings, source.bitsetFilterCache, source.searcherFactory, source.indexFieldDataService,
source.similarityService, source.scriptService, source.getXContentRegistry(), source.getWriteableRegistry(), source.mapperService, source.similarityService, source.scriptService, source.getXContentRegistry(),
source.client, source.reader, source.nowInMillis, source.fullyQualifiedIndex); source.getWriteableRegistry(), source.client, source.reader, source.nowInMillis, source.fullyQualifiedIndex);
this.types = source.getTypes();
} }
private QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache, private QueryShardContext(int shardId, IndexSettings indexSettings, BitsetFilterCache bitsetFilterCache,
Function<IndexReaderContext, IndexSearcher> searcherFactory,
BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService, BiFunction<MappedFieldType, String, IndexFieldData<?>> indexFieldDataLookup, MapperService mapperService,
SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry, SimilarityService similarityService, ScriptService scriptService, NamedXContentRegistry xContentRegistry,
NamedWriteableRegistry namedWriteableRegistry, Client client, IndexReader reader, LongSupplier nowInMillis, NamedWriteableRegistry namedWriteableRegistry, Client client, IndexReader reader, LongSupplier nowInMillis,
@ -131,6 +137,7 @@ public class QueryShardContext extends QueryRewriteContext {
this.similarityService = similarityService; this.similarityService = similarityService;
this.mapperService = mapperService; this.mapperService = mapperService;
this.bitsetFilterCache = bitsetFilterCache; this.bitsetFilterCache = bitsetFilterCache;
this.searcherFactory = searcherFactory;
this.indexFieldDataService = indexFieldDataLookup; this.indexFieldDataService = indexFieldDataLookup;
this.allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields(); this.allowUnmappedFields = indexSettings.isDefaultAllowUnmappedFields();
this.nestedScope = new NestedScope(); this.nestedScope = new NestedScope();
@ -175,6 +182,10 @@ public class QueryShardContext extends QueryRewriteContext {
return bitsetFilterCache.getBitSetProducer(filter); return bitsetFilterCache.getBitSetProducer(filter);
} }
public IndexSearcher newCachedSearcher(IndexReaderContext context) {
return searcherFactory.apply(context);
}
public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType) { public <IFD extends IndexFieldData<?>> IFD getForField(MappedFieldType fieldType) {
return (IFD) indexFieldDataService.apply(fieldType, fullyQualifiedIndex.getName()); return (IFD) indexFieldDataService.apply(fieldType, fullyQualifiedIndex.getName());
} }

View File

@ -195,7 +195,7 @@ public abstract class SortBuilder<T extends SortBuilder<T>> implements NamedWrit
} else { } else {
parentQuery = objectMapper.nestedTypeFilter(); parentQuery = objectMapper.nestedTypeFilter();
} }
return new Nested(context.bitsetFilter(parentQuery), childQuery, nestedSort); return new Nested(context.bitsetFilter(parentQuery), childQuery, nestedSort, context::newCachedSearcher);
} }
private static Query resolveNestedQuery(QueryShardContext context, NestedSortBuilder nestedSort, Query parentQuery) throws IOException { private static Query resolveNestedQuery(QueryShardContext context, NestedSortBuilder nestedSort, Query parentQuery) throws IOException {

View File

@ -163,7 +163,7 @@ public abstract class AbstractFieldDataTestCase extends ESSingleNodeTestCase {
protected Nested createNested(IndexSearcher searcher, Query parentFilter, Query childFilter) throws IOException { protected Nested createNested(IndexSearcher searcher, Query parentFilter, Query childFilter) throws IOException {
BitsetFilterCache s = indexService.cache().bitsetFilterCache(); BitsetFilterCache s = indexService.cache().bitsetFilterCache();
return new Nested(s.getBitSetProducer(parentFilter), childFilter, null); return new Nested(s.getBitSetProducer(parentFilter), childFilter, null, IndexSearcher::new);
} }
public void testEmpty() throws Exception { public void testEmpty() throws Exception {

View File

@ -178,7 +178,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
QueryShardContext context = new QueryShardContext(0, QueryShardContext context = new QueryShardContext(0,
new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(),
indexSettings), indexSettings),
null, null, null, null, null, xContentRegistry(), writableRegistry(), null, null, () -> nowInMillis, null); null, null, null, null, null, null, xContentRegistry(), writableRegistry(), null, null, () -> nowInMillis, null);
MappedFieldType ft = createDefaultFieldType(); MappedFieldType ft = createDefaultFieldType();
ft.setName("field"); ft.setName("field");
String date = "2015-10-12T14:10:55"; String date = "2015-10-12T14:10:55";
@ -200,7 +200,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
.put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build(); .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1).put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1).build();
QueryShardContext context = new QueryShardContext(0, QueryShardContext context = new QueryShardContext(0,
new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings), new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings),
null, null, null, null, null, xContentRegistry(), writableRegistry(), null, null, () -> nowInMillis, null); null, null, null, null, null, null, xContentRegistry(), writableRegistry(), null, null, () -> nowInMillis, null);
MappedFieldType ft = createDefaultFieldType(); MappedFieldType ft = createDefaultFieldType();
ft.setName("field"); ft.setName("field");
String date1 = "2015-10-12T14:10:55"; String date1 = "2015-10-12T14:10:55";

View File

@ -66,7 +66,7 @@ public class FieldNamesFieldTypeTests extends FieldTypeTestCase {
when(mapperService.simpleMatchToFullName("field_name")).thenReturn(Collections.singletonList("field_name")); when(mapperService.simpleMatchToFullName("field_name")).thenReturn(Collections.singletonList("field_name"));
QueryShardContext queryShardContext = new QueryShardContext(0, QueryShardContext queryShardContext = new QueryShardContext(0,
indexSettings, null, null, mapperService, null, null, null, null, null, null, () -> 0L, null); indexSettings, null, null, null, mapperService, null, null, null, null, null, null, () -> 0L, null);
fieldNamesFieldType.setEnabled(true); fieldNamesFieldType.setEnabled(true);
Query termQuery = fieldNamesFieldType.termQuery("field_name", queryShardContext); Query termQuery = fieldNamesFieldType.termQuery("field_name", queryShardContext);
assertEquals(new TermQuery(new Term(FieldNamesFieldMapper.CONTENT_TYPE, "field_name")), termQuery); assertEquals(new TermQuery(new Term(FieldNamesFieldMapper.CONTENT_TYPE, "field_name")), termQuery);

View File

@ -228,7 +228,7 @@ public class RangeFieldTypeTests extends FieldTypeTestCase {
Settings indexSettings = Settings.builder() Settings indexSettings = Settings.builder()
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAlphaOfLengthBetween(1, 10), indexSettings); IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAlphaOfLengthBetween(1, 10), indexSettings);
return new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(), return new QueryShardContext(0, idxSettings, null, null, null, null, null, null, xContentRegistry(),
writableRegistry(), null, null, () -> nowInMillis, null); writableRegistry(), null, null, () -> nowInMillis, null);
} }

View File

@ -364,7 +364,7 @@ public class IntervalQueryBuilderTests extends AbstractQueryTestCase<IntervalQue
QueryShardContext baseContext = createShardContext(); QueryShardContext baseContext = createShardContext();
QueryShardContext context = new QueryShardContext(baseContext.getShardId(), baseContext.getIndexSettings(), QueryShardContext context = new QueryShardContext(baseContext.getShardId(), baseContext.getIndexSettings(),
null, null, baseContext.getMapperService(), null, null, null, null, baseContext.getMapperService(), null,
scriptService, scriptService,
null, null, null, null, null, null); null, null, null, null, null, null);

View File

@ -128,7 +128,7 @@ public class QueryShardContextTests extends ESTestCase {
final long nowInMillis = randomNonNegativeLong(); final long nowInMillis = randomNonNegativeLong();
return new QueryShardContext( return new QueryShardContext(
0, indexSettings, null, (mappedFieldType, idxName) -> 0, indexSettings, null, null, (mappedFieldType, idxName) ->
mappedFieldType.fielddataBuilder(idxName).build(indexSettings, mappedFieldType, null, null, null) mappedFieldType.fielddataBuilder(idxName).build(indexSettings, mappedFieldType, null, null, null)
, mapperService, null, null, NamedXContentRegistry.EMPTY, new NamedWriteableRegistry(Collections.emptyList()), null, null, , mapperService, null, null, NamedXContentRegistry.EMPTY, new NamedWriteableRegistry(Collections.emptyList()), null, null,
() -> nowInMillis, clusterAlias); () -> nowInMillis, clusterAlias);

View File

@ -37,8 +37,8 @@ public class RangeQueryRewriteTests extends ESSingleNodeTestCase {
public void testRewriteMissingField() throws Exception { public void testRewriteMissingField() throws Exception {
IndexService indexService = createIndex("test"); IndexService indexService = createIndex("test");
IndexReader reader = new MultiReader(); IndexReader reader = new MultiReader();
QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, indexService.mapperService(), QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, null,
null, null, xContentRegistry(), writableRegistry(), null, reader, null, null); indexService.mapperService(), null, null, xContentRegistry(), writableRegistry(), null, reader, null, null);
RangeQueryBuilder range = new RangeQueryBuilder("foo"); RangeQueryBuilder range = new RangeQueryBuilder("foo");
assertEquals(Relation.DISJOINT, range.getRelation(context)); assertEquals(Relation.DISJOINT, range.getRelation(context));
} }
@ -54,8 +54,8 @@ public class RangeQueryRewriteTests extends ESSingleNodeTestCase {
.endObject().endObject()); .endObject().endObject());
indexService.mapperService().merge("type", indexService.mapperService().merge("type",
new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE);
QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, indexService.mapperService(), QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, null,
null, null, xContentRegistry(), writableRegistry(), null, null, null, null); indexService.mapperService(), null, null, xContentRegistry(), writableRegistry(), null, null, null, null);
RangeQueryBuilder range = new RangeQueryBuilder("foo"); RangeQueryBuilder range = new RangeQueryBuilder("foo");
// can't make assumptions on a missing reader, so it must return INTERSECT // can't make assumptions on a missing reader, so it must return INTERSECT
assertEquals(Relation.INTERSECTS, range.getRelation(context)); assertEquals(Relation.INTERSECTS, range.getRelation(context));
@ -73,8 +73,8 @@ public class RangeQueryRewriteTests extends ESSingleNodeTestCase {
indexService.mapperService().merge("type", indexService.mapperService().merge("type",
new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE); new CompressedXContent(mapping), MergeReason.MAPPING_UPDATE);
IndexReader reader = new MultiReader(); IndexReader reader = new MultiReader();
QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, indexService.mapperService(), QueryRewriteContext context = new QueryShardContext(0, indexService.getIndexSettings(), null, null, null,
null, null, xContentRegistry(), writableRegistry(), null, reader, null, null); indexService.mapperService(), null, null, xContentRegistry(), writableRegistry(), null, reader, null, null);
RangeQueryBuilder range = new RangeQueryBuilder("foo"); RangeQueryBuilder range = new RangeQueryBuilder("foo");
// no values -> DISJOINT // no values -> DISJOINT
assertEquals(Relation.DISJOINT, range.getRelation(context)); assertEquals(Relation.DISJOINT, range.getRelation(context));

View File

@ -793,6 +793,8 @@ public class NestedSortingTests extends AbstractFieldDataTestCase {
assertThat(searcher.doc(topFields.scoreDocs[0].doc).get("_id"), equalTo("4")); assertThat(searcher.doc(topFields.scoreDocs[0].doc).get("_id"), equalTo("4"));
assertThat(((FieldDoc) topFields.scoreDocs[0]).fields[0], equalTo(87L)); assertThat(((FieldDoc) topFields.scoreDocs[0]).fields[0], equalTo(87L));
} }
searcher.getIndexReader().close();
} }
private static TopFieldDocs search(QueryBuilder queryBuilder, FieldSortBuilder sortBuilder, QueryShardContext queryShardContext, private static TopFieldDocs search(QueryBuilder queryBuilder, FieldSortBuilder sortBuilder, QueryShardContext queryShardContext,

View File

@ -100,7 +100,7 @@ public class ExtendedBoundsTests extends ESTestCase {
SearchContext context = mock(SearchContext.class); SearchContext context = mock(SearchContext.class);
QueryShardContext qsc = new QueryShardContext(0, QueryShardContext qsc = new QueryShardContext(0,
new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings), null, null, null, null, new IndexSettings(IndexMetaData.builder("foo").settings(indexSettings).build(), indexSettings), null, null, null, null,
null, xContentRegistry(), writableRegistry(), null, null, () -> now, null); null, null, xContentRegistry(), writableRegistry(), null, null, () -> now, null);
when(context.getQueryShardContext()).thenReturn(qsc); when(context.getQueryShardContext()).thenReturn(qsc);
DateFormatter formatter = DateFormatter.forPattern("dateOptionalTime"); DateFormatter formatter = DateFormatter.forPattern("dateOptionalTime");
DocValueFormat format = new DocValueFormat.DateTime(formatter, ZoneOffset.UTC, DateFieldMapper.Resolution.MILLISECONDS); DocValueFormat format = new DocValueFormat.DateTime(formatter, ZoneOffset.UTC, DateFieldMapper.Resolution.MILLISECONDS);

View File

@ -407,7 +407,7 @@ public class ScriptedMetricAggregatorTests extends AggregatorTestCase {
MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, SCRIPTS, Collections.emptyMap()); MockScriptEngine scriptEngine = new MockScriptEngine(MockScriptEngine.NAME, SCRIPTS, Collections.emptyMap());
Map<String, ScriptEngine> engines = Collections.singletonMap(scriptEngine.getType(), scriptEngine); Map<String, ScriptEngine> engines = Collections.singletonMap(scriptEngine.getType(), scriptEngine);
ScriptService scriptService = new ScriptService(Settings.EMPTY, engines, ScriptModule.CORE_CONTEXTS); ScriptService scriptService = new ScriptService(Settings.EMPTY, engines, ScriptModule.CORE_CONTEXTS);
return new QueryShardContext(0, mapperService.getIndexSettings(), null, null, mapperService, null, scriptService, return new QueryShardContext(0, mapperService.getIndexSettings(), null, null, null, mapperService, null, scriptService,
xContentRegistry(), writableRegistry(), null, null, System::currentTimeMillis, null); xContentRegistry(), writableRegistry(), null, null, System::currentTimeMillis, null);
} }
} }

View File

@ -277,8 +277,8 @@ public class HighlightBuilderTests extends ESTestCase {
Index index = new Index(randomAlphaOfLengthBetween(1, 10), "_na_"); Index index = new Index(randomAlphaOfLengthBetween(1, 10), "_na_");
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, indexSettings); IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(index, indexSettings);
// shard context will only need indicesQueriesRegistry for building Query objects nested in highlighter // shard context will only need indicesQueriesRegistry for building Query objects nested in highlighter
QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(), QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, null,
namedWriteableRegistry, null, null, System::currentTimeMillis, null) { xContentRegistry(), namedWriteableRegistry, null, null, System::currentTimeMillis, null) {
@Override @Override
public MappedFieldType fieldMapper(String name) { public MappedFieldType fieldMapper(String name) {
TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name); TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name);

View File

@ -141,8 +141,8 @@ public class QueryRescorerBuilderTests extends ESTestCase {
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAlphaOfLengthBetween(1, 10), indexSettings); IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAlphaOfLengthBetween(1, 10), indexSettings);
// shard context will only need indicesQueriesRegistry for building Query objects nested in query rescorer // shard context will only need indicesQueriesRegistry for building Query objects nested in query rescorer
QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(), QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, null,
namedWriteableRegistry, null, null, () -> nowInMillis, null) { xContentRegistry(), namedWriteableRegistry, null, null, () -> nowInMillis, null) {
@Override @Override
public MappedFieldType fieldMapper(String name) { public MappedFieldType fieldMapper(String name) {
TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name); TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name);
@ -184,8 +184,8 @@ public class QueryRescorerBuilderTests extends ESTestCase {
.put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build(); .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT).build();
IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAlphaOfLengthBetween(1, 10), indexSettings); IndexSettings idxSettings = IndexSettingsModule.newIndexSettings(randomAlphaOfLengthBetween(1, 10), indexSettings);
// shard context will only need indicesQueriesRegistry for building Query objects nested in query rescorer // shard context will only need indicesQueriesRegistry for building Query objects nested in query rescorer
QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, xContentRegistry(), QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, null, null, null,
namedWriteableRegistry, null, null, () -> nowInMillis, null) { xContentRegistry(), namedWriteableRegistry, null, null, () -> nowInMillis, null) {
@Override @Override
public MappedFieldType fieldMapper(String name) { public MappedFieldType fieldMapper(String name) {
TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name); TextFieldMapper.Builder builder = new TextFieldMapper.Builder(name);

View File

@ -19,6 +19,7 @@
package org.elasticsearch.search.sort; package org.elasticsearch.search.sort;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.SortField; import org.apache.lucene.search.SortField;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.metadata.IndexMetaData;
@ -190,8 +191,8 @@ public abstract class AbstractSortTestCase<T extends SortBuilder<T>> extends EST
IndexFieldData.Builder builder = fieldType.fielddataBuilder(fieldIndexName); IndexFieldData.Builder builder = fieldType.fielddataBuilder(fieldIndexName);
return builder.build(idxSettings, fieldType, new IndexFieldDataCache.None(), null, null); return builder.build(idxSettings, fieldType, new IndexFieldDataCache.None(), null, null);
}; };
return new QueryShardContext(0, idxSettings, bitsetFilterCache, indexFieldDataLookup, null, null, scriptService, return new QueryShardContext(0, idxSettings, bitsetFilterCache, IndexSearcher::new, indexFieldDataLookup, null, null,
xContentRegistry(), namedWriteableRegistry, null, null, () -> randomNonNegativeLong(), null) { scriptService, xContentRegistry(), namedWriteableRegistry, null, null, () -> randomNonNegativeLong(), null) {
@Override @Override
public MappedFieldType fieldMapper(String name) { public MappedFieldType fieldMapper(String name) {

View File

@ -178,8 +178,8 @@ public abstract class AbstractSuggestionBuilderTestCase<SB extends SuggestionBui
invocation -> new NamedAnalyzer((String) invocation.getArguments()[0], AnalyzerScope.INDEX, new SimpleAnalyzer())); invocation -> new NamedAnalyzer((String) invocation.getArguments()[0], AnalyzerScope.INDEX, new SimpleAnalyzer()));
when(scriptService.compile(any(Script.class), any())).then(invocation -> new TestTemplateService.MockTemplateScript.Factory( when(scriptService.compile(any(Script.class), any())).then(invocation -> new TestTemplateService.MockTemplateScript.Factory(
((Script) invocation.getArguments()[0]).getIdOrCode())); ((Script) invocation.getArguments()[0]).getIdOrCode()));
QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, mapperService, null, scriptService, QueryShardContext mockShardContext = new QueryShardContext(0, idxSettings, null, null, null, mapperService, null,
xContentRegistry(), namedWriteableRegistry, null, null, System::currentTimeMillis, null); scriptService, xContentRegistry(), namedWriteableRegistry, null, null, System::currentTimeMillis, null);
SuggestionContext suggestionContext = suggestionBuilder.build(mockShardContext); SuggestionContext suggestionContext = suggestionBuilder.build(mockShardContext);
assertEquals(toBytesRef(suggestionBuilder.text()), suggestionContext.getText()); assertEquals(toBytesRef(suggestionBuilder.text()), suggestionContext.getText());

View File

@ -22,6 +22,7 @@ package org.elasticsearch.test;
import com.carrotsearch.randomizedtesting.RandomizedTest; import com.carrotsearch.randomizedtesting.RandomizedTest;
import com.carrotsearch.randomizedtesting.SeedUtils; import com.carrotsearch.randomizedtesting.SeedUtils;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.util.Accountable; import org.apache.lucene.util.Accountable;
import org.elasticsearch.Version; import org.elasticsearch.Version;
import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.ActionListener;
@ -418,8 +419,9 @@ public abstract class AbstractBuilderTestCase extends ESTestCase {
} }
QueryShardContext createShardContext(IndexReader reader) { QueryShardContext createShardContext(IndexReader reader) {
return new QueryShardContext(0, idxSettings, bitsetFilterCache, indexFieldDataService::getForField, mapperService, return new QueryShardContext(0, idxSettings, bitsetFilterCache, IndexSearcher::new, indexFieldDataService::getForField,
similarityService, scriptService, xContentRegistry, namedWriteableRegistry, this.client, reader, () -> nowInMillis, null); mapperService, similarityService, scriptService, xContentRegistry, namedWriteableRegistry, this.client, reader,
() -> nowInMillis, null);
} }
ScriptModule createScriptModule(List<ScriptPlugin> scriptPlugins) { ScriptModule createScriptModule(List<ScriptPlugin> scriptPlugins) {

View File

@ -41,8 +41,8 @@ public class MockSearchServiceTests extends ESTestCase {
public void testAssertNoInFlightContext() { public void testAssertNoInFlightContext() {
final long nowInMillis = randomNonNegativeLong(); final long nowInMillis = randomNonNegativeLong();
SearchContext s = new TestSearchContext(new QueryShardContext(0, SearchContext s = new TestSearchContext(new QueryShardContext(0,
new IndexSettings(EMPTY_INDEX_METADATA, Settings.EMPTY), null, null, null, null, null, xContentRegistry(), new IndexSettings(EMPTY_INDEX_METADATA, Settings.EMPTY), null, null, null, null, null, null,
writableRegistry(), null, null, () -> nowInMillis, null)) { xContentRegistry(), writableRegistry(), null, null, () -> nowInMillis, null)) {
@Override @Override
public SearchShardTarget shardTarget() { public SearchShardTarget shardTarget() {

View File

@ -83,8 +83,8 @@ public class SecurityIndexSearcherWrapperIntegrationTests extends AbstractBuilde
Client client = mock(Client.class); Client client = mock(Client.class);
when(client.settings()).thenReturn(Settings.EMPTY); when(client.settings()).thenReturn(Settings.EMPTY);
final long nowInMillis = randomNonNegativeLong(); final long nowInMillis = randomNonNegativeLong();
QueryShardContext realQueryShardContext = new QueryShardContext(shardId.id(), indexSettings, null, null, mapperService, null, QueryShardContext realQueryShardContext = new QueryShardContext(shardId.id(), indexSettings, null, null, null, mapperService,
null, xContentRegistry(), writableRegistry(), client, null, () -> nowInMillis, null); null, null, xContentRegistry(), writableRegistry(), client, null, () -> nowInMillis, null);
QueryShardContext queryShardContext = spy(realQueryShardContext); QueryShardContext queryShardContext = spy(realQueryShardContext);
IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY); IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY);
BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() { BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() {
@ -206,8 +206,8 @@ public class SecurityIndexSearcherWrapperIntegrationTests extends AbstractBuilde
Client client = mock(Client.class); Client client = mock(Client.class);
when(client.settings()).thenReturn(Settings.EMPTY); when(client.settings()).thenReturn(Settings.EMPTY);
final long nowInMillis = randomNonNegativeLong(); final long nowInMillis = randomNonNegativeLong();
QueryShardContext realQueryShardContext = new QueryShardContext(shardId.id(), indexSettings, null, null, mapperService, null, QueryShardContext realQueryShardContext = new QueryShardContext(shardId.id(), indexSettings, null, null, null, mapperService,
null, xContentRegistry(), writableRegistry(), client, null, () -> nowInMillis, null); null, null, xContentRegistry(), writableRegistry(), client, null, () -> nowInMillis, null);
QueryShardContext queryShardContext = spy(realQueryShardContext); QueryShardContext queryShardContext = spy(realQueryShardContext);
IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY); IndexSettings settings = IndexSettingsModule.newIndexSettings("_index", Settings.EMPTY);
BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() { BitsetFilterCache bitsetFilterCache = new BitsetFilterCache(settings, new BitsetFilterCache.Listener() {

View File

@ -91,7 +91,7 @@ public class RollupIndexerIndexingTests extends AggregatorTestCase {
private void setup() { private void setup() {
settings = createIndexSettings(); settings = createIndexSettings();
queryShardContext = new QueryShardContext(0, settings, queryShardContext = new QueryShardContext(0, settings,
null, null, null, null, null, null, null, null, null, null, null,
null, null, null, null, () -> 0L, null); null, null, null, null, () -> 0L, null);
} }