Skip to content

Commit 1ff721e

Browse files
authored
Expose ShardSearchStats in SearchExecutionContext (elastic#141709)
This commit makes ShardSearchStats available in SearchExecutionContext and consolidates the two existing constructors.
1 parent 9463a07 commit 1ff721e

File tree

54 files changed

+257
-142
lines changed

Some content is hidden

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

54 files changed

+257
-142
lines changed

benchmarks/src/main/java/org/elasticsearch/benchmark/search/QueryParserHelperBenchmark.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.common.compress.CompressedXContent;
2525
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
2626
import org.elasticsearch.common.lucene.Lucene;
27+
import org.elasticsearch.common.settings.ClusterSettings;
2728
import org.elasticsearch.common.settings.Settings;
2829
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
2930
import org.elasticsearch.core.IOUtils;
@@ -38,6 +39,8 @@
3839
import org.elasticsearch.index.mapper.SourceToParse;
3940
import org.elasticsearch.index.query.SearchExecutionContext;
4041
import org.elasticsearch.index.search.QueryParserHelper;
42+
import org.elasticsearch.index.search.stats.SearchStatsSettings;
43+
import org.elasticsearch.index.search.stats.ShardSearchStats;
4144
import org.elasticsearch.index.shard.IndexShard;
4245
import org.elasticsearch.index.similarity.SimilarityService;
4346
import org.elasticsearch.indices.IndicesModule;
@@ -157,7 +160,9 @@ protected SearchExecutionContext buildSearchExecutionContext() {
157160
() -> true,
158161
null,
159162
Collections.emptyMap(),
160-
MapperMetrics.NOOP
163+
null,
164+
MapperMetrics.NOOP,
165+
new ShardSearchStats(new SearchStatsSettings(new ClusterSettings(Settings.EMPTY, ClusterSettings.BUILT_IN_CLUSTER_SETTINGS)))
161166
);
162167
}
163168

modules/analysis-common/src/test/java/org/elasticsearch/analysis/common/DisableGraphQueryTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void setup() {
8080
"text_shingle_unigram",
8181
"type=text,analyzer=text_shingle_unigram"
8282
);
83-
searchExecutionContext = indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap());
83+
searchExecutionContext = indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap(), null, null);
8484

8585
// parsed queries for "text_shingle_unigram:(foo bar baz)" with query parsers
8686
// that ignores position length attribute

modules/lang-painless/src/main/java/org/elasticsearch/painless/action/PainlessExecuteAction.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,9 @@ private static Response prepareRamIndex(
881881
searcher,
882882
() -> absoluteStartMillis,
883883
null,
884-
emptyMap()
884+
emptyMap(),
885+
null,
886+
null
885887
);
886888
return handler.apply(context, indexReader.leaves().get(0));
887889
}

modules/lang-painless/src/test/java/org/elasticsearch/painless/NeedsScoreTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public void testNeedsScores() {
3838
contexts.put(NumberSortScript.CONTEXT, PAINLESS_BASE_WHITELIST);
3939
PainlessScriptEngine service = new PainlessScriptEngine(Settings.EMPTY, contexts);
4040

41-
SearchExecutionContext searchExecutionContext = index.newSearchExecutionContext(0, 0, null, () -> 0, null, emptyMap());
41+
SearchExecutionContext searchExecutionContext = index.newSearchExecutionContext(0, 0, null, () -> 0, null, emptyMap(), null, null);
4242

4343
NumberSortScript.Factory factory = service.compile(null, "1.2", NumberSortScript.CONTEXT, Collections.emptyMap());
4444
NumberSortScript.LeafFactory ss = factory.newFactory(Collections.emptyMap(), searchExecutionContext.lookup());

modules/lang-painless/src/test/java/org/elasticsearch/painless/ScoreScriptTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void testNeedsTermStats() {
4040
contexts.put(ScoreScript.CONTEXT, whitelists);
4141
PainlessScriptEngine service = new PainlessScriptEngine(Settings.EMPTY, contexts);
4242

43-
SearchExecutionContext searchExecutionContext = index.newSearchExecutionContext(0, 0, null, () -> 0, null, emptyMap());
43+
SearchExecutionContext searchExecutionContext = index.newSearchExecutionContext(0, 0, null, () -> 0, null, emptyMap(), null, null);
4444

4545
ScoreScript.Factory factory = service.compile(null, "1.2", ScoreScript.CONTEXT, Collections.emptyMap());
4646
ScoreScript.LeafFactory ss = factory.newFactory(Collections.emptyMap(), searchExecutionContext.lookup());

modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorFieldMapperTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,7 @@ public void testQueryWithRewrite() throws Exception {
635635
BytesRef qbSource = doc.rootDoc().getFields(fieldType.queryBuilderField.name()).get(0).binaryValue();
636636
SearchExecutionContext searchExecutionContext = indexService.newSearchExecutionContext(randomInt(20), 0, null, () -> {
637637
throw new UnsupportedOperationException();
638-
}, null, emptyMap());
638+
}, null, emptyMap(), null, null);
639639
PlainActionFuture<QueryBuilder> future = new PlainActionFuture<>();
640640
Rewriteable.rewriteAndFetch(queryBuilder, searchExecutionContext, future);
641641
assertQueryBuilder(qbSource, future.get());

modules/percolator/src/test/java/org/elasticsearch/percolator/PercolatorQuerySearchTests.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ public void testRangeQueriesWithNow() throws Exception {
322322
searcher,
323323
() -> currentTime[0],
324324
null,
325-
emptyMap()
325+
emptyMap(),
326+
null,
327+
null
326328
);
327329

328330
BytesReference source = BytesReference.bytes(

server/src/main/java/org/elasticsearch/action/admin/indices/template/post/TransportSimulateIndexTemplateAction.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,7 @@ public static Template resolveTemplate(
328328
xContentRegistry,
329329
// the context is only used for validation so it's fine to pass fake values for the
330330
// shard id and the current timestamp
331-
tempIndexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap()),
331+
tempIndexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap(), null, null),
332332
IndexService.dateMathExpressionResolverAt(),
333333
systemIndices::isSystemName
334334
)

server/src/main/java/org/elasticsearch/action/fieldcaps/FieldCapabilitiesFetcher.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,9 @@ private FieldCapabilitiesIndexResponse doFetch(
109109
searcher,
110110
() -> nowInMillis,
111111
null,
112-
runtimeFields
112+
runtimeFields,
113+
null,
114+
null
113115
);
114116
var indexMode = searchExecutionContext.getIndexSettings().getMode();
115117
if (searcher != null && canMatchShard(shardId, indexFilter, nowInMillis, searchExecutionContext) == false) {

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ private ClusterState applyCreateIndexRequestWithV1Templates(
732732
// the context is only used for validation so it's fine to pass fake values for the
733733
// shard id and the current timestamp
734734
xContentRegistry,
735-
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap()),
735+
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap(), null, null),
736736
IndexService.dateMathExpressionResolverAt(request.getNameResolvedAt()),
737737
systemIndices::isSystemName
738738
),
@@ -825,7 +825,7 @@ private ClusterState applyCreateIndexRequestWithV2Template(
825825
projectMetadata,
826826
xContentRegistry,
827827
// the context is used ony for validation so it's fine to pass fake values for the shard id and the current timestamp
828-
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap()),
828+
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap(), null, null),
829829
IndexService.dateMathExpressionResolverAt(request.getNameResolvedAt()),
830830
systemIndices::isSystemName
831831
),
@@ -880,7 +880,7 @@ private ClusterState applyCreateIndexRequestForSystemIndex(
880880
// the context is only used for validation so it's fine to pass fake values for the
881881
// shard id and the current timestamp
882882
xContentRegistry,
883-
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap()),
883+
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap(), null, null),
884884
IndexService.dateMathExpressionResolverAt(request.getNameResolvedAt()),
885885
systemIndices::isSystemName
886886
),
@@ -947,7 +947,7 @@ private ClusterState applyCreateIndexRequestForSystemDataStream(
947947
// the context is only used for validation so it's fine to pass fake values for the
948948
// shard id and the current timestamp
949949
xContentRegistry,
950-
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap()),
950+
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap(), null, null),
951951
IndexService.dateMathExpressionResolverAt(request.getNameResolvedAt()),
952952
systemIndices::isSystemName
953953
),
@@ -1056,7 +1056,7 @@ private ClusterState applyCreateIndexRequestWithExistingMetadata(
10561056
xContentRegistry,
10571057
// the context is only used for validation so it's fine to pass fake values for the
10581058
// shard id and the current timestamp
1059-
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap()),
1059+
indexService.newSearchExecutionContext(0, 0, null, () -> 0L, null, emptyMap(), null, null),
10601060
IndexService.dateMathExpressionResolverAt(request.getNameResolvedAt()),
10611061
systemIndices::isSystemName
10621062
),

0 commit comments

Comments
 (0)