Skip to content

Commit 691886f

Browse files
committed
Switch SearchExecutionContext to new createParser
In elastic#79814 I deprecated many variants of XContent#createParser in favor of some new variants that bundle many of the arguments. This replaces the variants used by the search execution context with the new variants.
1 parent 3c23a9e commit 691886f

File tree

20 files changed

+58
-72
lines changed

20 files changed

+58
-72
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void testStoringQueryBuilders() throws IOException {
7575
SearchExecutionContext searchExecutionContext = mock(SearchExecutionContext.class);
7676
when(searchExecutionContext.indexVersionCreated()).thenReturn(version);
7777
when(searchExecutionContext.getWriteableRegistry()).thenReturn(writableRegistry());
78-
when(searchExecutionContext.getXContentRegistry()).thenReturn(xContentRegistry());
78+
when(searchExecutionContext.getParserConfig()).thenReturn(parserConfig());
7979
when(searchExecutionContext.getForField(fieldMapper.fieldType())).thenReturn(
8080
new BytesBinaryIndexFieldData(fieldMapper.name(), CoreValuesSourceType.KEYWORD)
8181
);

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import org.elasticsearch.index.mapper.DateFieldMapper;
1616
import org.elasticsearch.index.mapper.MappedFieldType;
1717
import org.elasticsearch.index.shard.IndexLongFieldRange;
18-
import org.elasticsearch.xcontent.NamedXContentRegistry;
18+
import org.elasticsearch.xcontent.XContentParserConfiguration;
1919

2020
import java.util.function.LongSupplier;
2121

@@ -32,15 +32,15 @@ public class CoordinatorRewriteContext extends QueryRewriteContext {
3232
private final DateFieldMapper.DateFieldType timestampFieldType;
3333

3434
public CoordinatorRewriteContext(
35-
NamedXContentRegistry xContentRegistry,
35+
XContentParserConfiguration parserConfig,
3636
NamedWriteableRegistry writeableRegistry,
3737
Client client,
3838
LongSupplier nowInMillis,
3939
Index index,
4040
IndexLongFieldRange indexLongFieldRange,
4141
DateFieldMapper.DateFieldType timestampFieldType
4242
) {
43-
super(xContentRegistry, writeableRegistry, client, nowInMillis);
43+
super(parserConfig, writeableRegistry, client, nowInMillis);
4444
this.index = index;
4545
this.indexLongFieldRange = indexLongFieldRange;
4646
this.timestampFieldType = timestampFieldType;

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

+5-13
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,29 @@
1616
import org.elasticsearch.index.Index;
1717
import org.elasticsearch.index.mapper.DateFieldMapper;
1818
import org.elasticsearch.index.shard.IndexLongFieldRange;
19-
import org.elasticsearch.xcontent.NamedXContentRegistry;
19+
import org.elasticsearch.xcontent.XContentParserConfiguration;
2020

2121
import java.util.function.Function;
2222
import java.util.function.LongSupplier;
2323
import java.util.function.Supplier;
2424

2525
public class CoordinatorRewriteContextProvider {
26-
private final NamedXContentRegistry xContentRegistry;
26+
private final XContentParserConfiguration parserConfig;
2727
private final NamedWriteableRegistry writeableRegistry;
2828
private final Client client;
2929
private final LongSupplier nowInMillis;
3030
private final Supplier<ClusterState> clusterStateSupplier;
3131
private final Function<Index, DateFieldMapper.DateFieldType> mappingSupplier;
3232

3333
public CoordinatorRewriteContextProvider(
34-
NamedXContentRegistry xContentRegistry,
34+
XContentParserConfiguration parserConfig,
3535
NamedWriteableRegistry writeableRegistry,
3636
Client client,
3737
LongSupplier nowInMillis,
3838
Supplier<ClusterState> clusterStateSupplier,
3939
Function<Index, DateFieldMapper.DateFieldType> mappingSupplier
4040
) {
41-
this.xContentRegistry = xContentRegistry;
41+
this.parserConfig = parserConfig;
4242
this.writeableRegistry = writeableRegistry;
4343
this.client = client;
4444
this.nowInMillis = nowInMillis;
@@ -62,14 +62,6 @@ public CoordinatorRewriteContext getCoordinatorRewriteContext(Index index) {
6262
}
6363

6464
IndexLongFieldRange timestampRange = indexMetadata.getTimestampRange();
65-
return new CoordinatorRewriteContext(
66-
xContentRegistry,
67-
writeableRegistry,
68-
client,
69-
nowInMillis,
70-
index,
71-
timestampRange,
72-
dateFieldType
73-
);
65+
return new CoordinatorRewriteContext(parserConfig, writeableRegistry, client, nowInMillis, index, timestampRange, dateFieldType);
7466
}
7567
}

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

+6-6
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import org.elasticsearch.client.Client;
1212
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
1313
import org.elasticsearch.common.util.concurrent.CountDown;
14-
import org.elasticsearch.xcontent.NamedXContentRegistry;
1514
import org.elasticsearch.xcontent.XContentParser;
15+
import org.elasticsearch.xcontent.XContentParserConfiguration;
1616

1717
import java.util.ArrayList;
1818
import java.util.List;
@@ -23,20 +23,20 @@
2323
* Context object used to rewrite {@link QueryBuilder} instances into simplified version.
2424
*/
2525
public class QueryRewriteContext {
26-
private final NamedXContentRegistry xContentRegistry;
26+
private final XContentParserConfiguration parserConfiguration;
2727
private final NamedWriteableRegistry writeableRegistry;
2828
protected final Client client;
2929
protected final LongSupplier nowInMillis;
3030
private final List<BiConsumer<Client, ActionListener<?>>> asyncActions = new ArrayList<>();
3131

3232
public QueryRewriteContext(
33-
NamedXContentRegistry xContentRegistry,
33+
XContentParserConfiguration parserConfiguration,
3434
NamedWriteableRegistry writeableRegistry,
3535
Client client,
3636
LongSupplier nowInMillis
3737
) {
3838

39-
this.xContentRegistry = xContentRegistry;
39+
this.parserConfiguration = parserConfiguration;
4040
this.writeableRegistry = writeableRegistry;
4141
this.client = client;
4242
this.nowInMillis = nowInMillis;
@@ -45,8 +45,8 @@ public QueryRewriteContext(
4545
/**
4646
* The registry used to build new {@link XContentParser}s. Contains registered named parsers needed to parse the query.
4747
*/
48-
public NamedXContentRegistry getXContentRegistry() {
49-
return xContentRegistry;
48+
public XContentParserConfiguration getParserConfig() {
49+
return parserConfiguration;
5050
}
5151

5252
/**

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

+7-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.common.io.stream.NamedWriteableRegistry;
2525
import org.elasticsearch.common.lucene.search.Queries;
2626
import org.elasticsearch.common.regex.Regex;
27+
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
2728
import org.elasticsearch.core.CheckedFunction;
2829
import org.elasticsearch.core.Nullable;
2930
import org.elasticsearch.index.Index;
@@ -59,6 +60,7 @@
5960
import org.elasticsearch.transport.RemoteClusterAware;
6061
import org.elasticsearch.xcontent.NamedXContentRegistry;
6162
import org.elasticsearch.xcontent.XContentParser;
63+
import org.elasticsearch.xcontent.XContentParserConfiguration;
6264

6365
import java.io.IOException;
6466
import java.util.Collections;
@@ -144,7 +146,8 @@ public SearchExecutionContext(
144146
mappingLookup,
145147
similarityService,
146148
scriptService,
147-
xContentRegistry,
149+
// TODO pass the parser configuration into this method?
150+
XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE).withRegistry(xContentRegistry),
148151
namedWriteableRegistry,
149152
client,
150153
searcher,
@@ -172,7 +175,7 @@ public SearchExecutionContext(SearchExecutionContext source) {
172175
source.mappingLookup,
173176
source.similarityService,
174177
source.scriptService,
175-
source.getXContentRegistry(),
178+
source.getParserConfig(),
176179
source.getWriteableRegistry(),
177180
source.client,
178181
source.searcher,
@@ -196,7 +199,7 @@ private SearchExecutionContext(
196199
MappingLookup mappingLookup,
197200
SimilarityService similarityService,
198201
ScriptService scriptService,
199-
NamedXContentRegistry xContentRegistry,
202+
XContentParserConfiguration parserConfig,
200203
NamedWriteableRegistry namedWriteableRegistry,
201204
Client client,
202205
IndexSearcher searcher,
@@ -208,7 +211,7 @@ private SearchExecutionContext(
208211
Map<String, MappedFieldType> runtimeMappings,
209212
Predicate<String> allowedFields
210213
) {
211-
super(xContentRegistry, namedWriteableRegistry, client, nowInMillis);
214+
super(parserConfig, namedWriteableRegistry, client, nowInMillis);
212215
this.shardId = shardId;
213216
this.shardRequestIndex = shardRequestIndex;
214217
this.similarityService = similarityService;

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

+1-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import org.elasticsearch.common.bytes.BytesReference;
1616
import org.elasticsearch.common.io.stream.StreamInput;
1717
import org.elasticsearch.common.io.stream.StreamOutput;
18-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1918
import org.elasticsearch.xcontent.ParseField;
2019
import org.elasticsearch.xcontent.XContentBuilder;
2120
import org.elasticsearch.xcontent.XContentFactory;
@@ -148,10 +147,7 @@ protected boolean doEquals(WrapperQueryBuilder other) {
148147

149148
@Override
150149
protected QueryBuilder doRewrite(QueryRewriteContext context) throws IOException {
151-
try (
152-
XContentParser qSourceParser = XContentFactory.xContent(source)
153-
.createParser(context.getXContentRegistry(), LoggingDeprecationHandler.INSTANCE, source)
154-
) {
150+
try (XContentParser qSourceParser = XContentFactory.xContent(source).createParser(context.getParserConfig(), source)) {
155151

156152
final QueryBuilder queryBuilder = parseInnerQueryBuilder(qSourceParser).rewrite(context);
157153
if (boost() != DEFAULT_BOOST || queryName() != null) {

server/src/main/java/org/elasticsearch/indices/IndicesService.java

+6-2
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
import org.elasticsearch.xcontent.NamedXContentRegistry;
132132
import org.elasticsearch.xcontent.XContentFactory;
133133
import org.elasticsearch.xcontent.XContentParser;
134+
import org.elasticsearch.xcontent.XContentParserConfiguration;
134135
import org.elasticsearch.xcontent.XContentType;
135136

136137
import java.io.Closeable;
@@ -203,6 +204,7 @@ public class IndicesService extends AbstractLifecycleComponent
203204
private final PluginsService pluginsService;
204205
private final NodeEnvironment nodeEnv;
205206
private final NamedXContentRegistry xContentRegistry;
207+
private final XContentParserConfiguration parserConfig;
206208
private final TimeValue shardsClosedTimeout;
207209
private final AnalysisRegistry analysisRegistry;
208210
private final IndexNameExpressionResolver indexNameExpressionResolver;
@@ -283,6 +285,8 @@ public IndicesService(
283285
this.pluginsService = pluginsService;
284286
this.nodeEnv = nodeEnv;
285287
this.xContentRegistry = xContentRegistry;
288+
this.parserConfig = XContentParserConfiguration.EMPTY.withDeprecationHandler(LoggingDeprecationHandler.INSTANCE)
289+
.withRegistry(xContentRegistry);
286290
this.valuesSourceRegistry = valuesSourceRegistry;
287291
this.shardsClosedTimeout = settings.getAsTime(INDICES_SHARDS_CLOSED_TIMEOUT, new TimeValue(1, TimeUnit.DAYS));
288292
this.analysisRegistry = analysisRegistry;
@@ -1683,12 +1687,12 @@ public AliasFilter buildAliasFilter(ClusterState state, String index, Set<String
16831687
* Returns a new {@link QueryRewriteContext} with the given {@code now} provider
16841688
*/
16851689
public QueryRewriteContext getRewriteContext(LongSupplier nowInMillis) {
1686-
return new QueryRewriteContext(xContentRegistry, namedWriteableRegistry, client, nowInMillis);
1690+
return new QueryRewriteContext(parserConfig, namedWriteableRegistry, client, nowInMillis);
16871691
}
16881692

16891693
public CoordinatorRewriteContextProvider getCoordinatorRewriteContextProvider(LongSupplier nowInMillis) {
16901694
return new CoordinatorRewriteContextProvider(
1691-
xContentRegistry,
1695+
parserConfig,
16921696
namedWriteableRegistry,
16931697
client,
16941698
nowInMillis,

server/src/main/java/org/elasticsearch/search/suggest/completion/CompletionSuggestionBuilder.java

+4-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import org.elasticsearch.common.io.stream.StreamInput;
1313
import org.elasticsearch.common.io.stream.StreamOutput;
1414
import org.elasticsearch.common.unit.Fuzziness;
15-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
1615
import org.elasticsearch.common.xcontent.XContentHelper;
1716
import org.elasticsearch.index.mapper.CompletionFieldMapper;
1817
import org.elasticsearch.index.mapper.MappedFieldType;
@@ -21,13 +20,13 @@
2120
import org.elasticsearch.search.suggest.SuggestionSearchContext.SuggestionContext;
2221
import org.elasticsearch.search.suggest.completion.context.ContextMapping;
2322
import org.elasticsearch.search.suggest.completion.context.ContextMappings;
24-
import org.elasticsearch.xcontent.NamedXContentRegistry;
2523
import org.elasticsearch.xcontent.ObjectParser;
2624
import org.elasticsearch.xcontent.ParseField;
2725
import org.elasticsearch.xcontent.ToXContent;
2826
import org.elasticsearch.xcontent.XContentBuilder;
2927
import org.elasticsearch.xcontent.XContentFactory;
3028
import org.elasticsearch.xcontent.XContentParser;
29+
import org.elasticsearch.xcontent.XContentParserConfiguration;
3130
import org.elasticsearch.xcontent.XContentType;
3231

3332
import java.io.IOException;
@@ -288,7 +287,7 @@ public SuggestionContext build(SearchExecutionContext context) throws IOExceptio
288287
if (type.hasContextMappings() && contextBytes != null) {
289288
Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = parseContextBytes(
290289
contextBytes,
291-
context.getXContentRegistry(),
290+
context.getParserConfig(),
292291
type.getContextMappings()
293292
);
294293
suggestionContext.setQueryContexts(queryContexts);
@@ -301,17 +300,10 @@ public SuggestionContext build(SearchExecutionContext context) throws IOExceptio
301300

302301
static Map<String, List<ContextMapping.InternalQueryContext>> parseContextBytes(
303302
BytesReference contextBytes,
304-
NamedXContentRegistry xContentRegistry,
303+
XContentParserConfiguration parserConfig,
305304
ContextMappings contextMappings
306305
) throws IOException {
307-
try (
308-
XContentParser contextParser = XContentHelper.createParser(
309-
xContentRegistry,
310-
LoggingDeprecationHandler.INSTANCE,
311-
contextBytes,
312-
CONTEXT_BYTES_XCONTENT_TYPE
313-
)
314-
) {
306+
try (XContentParser contextParser = XContentHelper.createParser(parserConfig, contextBytes, CONTEXT_BYTES_XCONTENT_TYPE)) {
315307
contextParser.nextToken();
316308
Map<String, List<ContextMapping.InternalQueryContext>> queryContexts = new HashMap<>(contextMappings.size());
317309
assert contextParser.currentToken() == XContentParser.Token.START_OBJECT;

server/src/main/java/org/elasticsearch/search/suggest/phrase/PhraseSuggester.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import org.apache.lucene.util.CharsRefBuilder;
2020
import org.elasticsearch.common.lucene.Lucene;
2121
import org.elasticsearch.common.text.Text;
22-
import org.elasticsearch.common.xcontent.LoggingDeprecationHandler;
2322
import org.elasticsearch.index.query.AbstractQueryBuilder;
2423
import org.elasticsearch.index.query.ParsedQuery;
2524
import org.elasticsearch.index.query.QueryBuilder;
@@ -132,7 +131,7 @@ public Suggestion<? extends Entry<? extends Option>> innerExecute(
132131
final String querySource = scriptFactory.newInstance(vars).execute();
133132
try (
134133
XContentParser parser = XContentFactory.xContent(querySource)
135-
.createParser(searchExecutionContext.getXContentRegistry(), LoggingDeprecationHandler.INSTANCE, querySource)
134+
.createParser(searchExecutionContext.getParserConfig(), querySource)
136135
) {
137136
QueryBuilder innerQueryBuilder = AbstractQueryBuilder.parseInnerQueryBuilder(parser);
138137
final ParsedQuery parsedQuery = searchExecutionContext.toQuery(innerQueryBuilder);

server/src/test/java/org/elasticsearch/action/search/CanMatchPreFilterSearchPhaseTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
import org.elasticsearch.threadpool.TestThreadPool;
4646
import org.elasticsearch.threadpool.ThreadPool;
4747
import org.elasticsearch.transport.Transport;
48-
import org.elasticsearch.xcontent.NamedXContentRegistry;
48+
import org.elasticsearch.xcontent.XContentParserConfiguration;
4949

5050
import java.io.IOException;
5151
import java.util.ArrayList;
@@ -822,7 +822,7 @@ private void addIndexMinMaxTimestamps(Index index, String fieldName, long minTim
822822

823823
public CoordinatorRewriteContextProvider build() {
824824
return new CoordinatorRewriteContextProvider(
825-
NamedXContentRegistry.EMPTY,
825+
XContentParserConfiguration.EMPTY,
826826
mock(NamedWriteableRegistry.class),
827827
mock(Client.class),
828828
System::currentTimeMillis,

server/src/test/java/org/elasticsearch/index/mapper/DateFieldTypeTests.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public class DateFieldTypeTests extends FieldTypeTestCase {
5353
private static final long nowInMillis = 0;
5454

5555
public void testIsFieldWithinRangeEmptyReader() throws IOException {
56-
QueryRewriteContext context = new QueryRewriteContext(xContentRegistry(), writableRegistry(), null, () -> nowInMillis);
56+
QueryRewriteContext context = new QueryRewriteContext(parserConfig(), writableRegistry(), null, () -> nowInMillis);
5757
IndexReader reader = new MultiReader();
5858
DateFieldType ft = new DateFieldType("my_date");
5959
assertEquals(
@@ -90,7 +90,7 @@ public void isFieldWithinRangeTestCase(DateFieldType ft) throws IOException {
9090
doTestIsFieldWithinQuery(ft, reader, ZoneOffset.UTC, null);
9191
doTestIsFieldWithinQuery(ft, reader, ZoneOffset.UTC, alternateFormat);
9292

93-
QueryRewriteContext context = new QueryRewriteContext(xContentRegistry(), writableRegistry(), null, () -> nowInMillis);
93+
QueryRewriteContext context = new QueryRewriteContext(parserConfig(), writableRegistry(), null, () -> nowInMillis);
9494

9595
// Fields with no value indexed.
9696
DateFieldType ft2 = new DateFieldType("my_date2");
@@ -102,7 +102,7 @@ public void isFieldWithinRangeTestCase(DateFieldType ft) throws IOException {
102102

103103
private void doTestIsFieldWithinQuery(DateFieldType ft, DirectoryReader reader, ZoneId zone, DateMathParser alternateFormat)
104104
throws IOException {
105-
QueryRewriteContext context = new QueryRewriteContext(xContentRegistry(), writableRegistry(), null, () -> nowInMillis);
105+
QueryRewriteContext context = new QueryRewriteContext(parserConfig(), writableRegistry(), null, () -> nowInMillis);
106106
assertEquals(
107107
Relation.INTERSECTS,
108108
ft.isFieldWithinQuery(reader, "2015-10-09", "2016-01-02", randomBoolean(), randomBoolean(), zone, null, context)

0 commit comments

Comments
 (0)