Adapt to "Switch to ParseField for query names"
A ParseField object is now required to register queries against the SearchModule rather than the QueryParser#names method. ParseField handles camel case automatically. Also this allows us to log deprecation warnings (or fail in strict mode) when deprecated names are used for queries (e.g. "in", "mlt", "fuzzy_match" etc.) Original commit: elastic/x-pack-elasticsearch@b0146e6e3d
This commit is contained in:
parent
9a5e60b58f
commit
0a9b72233e
|
@ -11,6 +11,7 @@ import org.elasticsearch.action.search.SearchType;
|
|||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.common.Strings;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.ToXContent;
|
||||
|
@ -18,6 +19,7 @@ import org.elasticsearch.common.xcontent.XContentBuilder;
|
|||
import org.elasticsearch.common.xcontent.XContentHelper;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.common.xcontent.XContentType;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchAllQueryParser;
|
||||
import org.elasticsearch.index.query.QueryBuilders;
|
||||
import org.elasticsearch.index.query.QueryParseContext;
|
||||
|
@ -133,7 +135,8 @@ public class WatcherUtilsTests extends ESTestCase {
|
|||
builder = WatcherUtils.writeSearchRequest(expectedRequest, builder, ToXContent.EMPTY_PARAMS);
|
||||
XContentParser parser = XContentHelper.createParser(builder.bytes());
|
||||
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, singletonMap("match_all", new MatchAllQueryParser()));
|
||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY,
|
||||
singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryParser.QUERY_NAME_FIELD, new MatchAllQueryParser())));
|
||||
QueryParseContext context = new QueryParseContext(registry);
|
||||
context.reset(parser);
|
||||
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null);
|
||||
|
@ -221,7 +224,8 @@ public class WatcherUtilsTests extends ESTestCase {
|
|||
|
||||
XContentParser parser = XContentHelper.createParser(builder.bytes());
|
||||
assertThat(parser.nextToken(), equalTo(XContentParser.Token.START_OBJECT));
|
||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, singletonMap("match_all", new MatchAllQueryParser()));
|
||||
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY,
|
||||
singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryParser.QUERY_NAME_FIELD, new MatchAllQueryParser())));
|
||||
QueryParseContext context = new QueryParseContext(registry);
|
||||
context.reset(parser);
|
||||
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null, null);
|
||||
|
|
|
@ -7,12 +7,14 @@ package org.elasticsearch.watcher.watch;
|
|||
|
||||
import org.elasticsearch.ElasticsearchParseException;
|
||||
import org.elasticsearch.common.bytes.BytesReference;
|
||||
import org.elasticsearch.common.collect.Tuple;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.unit.TimeValue;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.elasticsearch.index.query.MatchAllQueryBuilder;
|
||||
import org.elasticsearch.index.query.MatchAllQueryParser;
|
||||
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
|
@ -350,8 +352,8 @@ public class WatchTests extends ESTestCase {
|
|||
Map<String, InputFactory> parsers = new HashMap<>();
|
||||
switch (input.type()) {
|
||||
case SearchInput.TYPE:
|
||||
IndicesQueriesRegistry queryRegistry = new IndicesQueriesRegistry(Settings.EMPTY,
|
||||
singletonMap("match_all", new MatchAllQueryParser()));
|
||||
IndicesQueriesRegistry queryRegistry = new IndicesQueriesRegistry(Settings.EMPTY, singletonMap(
|
||||
MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryParser.QUERY_NAME_FIELD, new MatchAllQueryParser())));
|
||||
parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, queryRegistry, null, null));
|
||||
return new InputRegistry(parsers);
|
||||
default:
|
||||
|
@ -418,7 +420,7 @@ public class WatchTests extends ESTestCase {
|
|||
|
||||
private TransformRegistry transformRegistry() {
|
||||
IndicesQueriesRegistry queryRegistry = new IndicesQueriesRegistry(Settings.EMPTY,
|
||||
singletonMap("match_all", new MatchAllQueryParser()));
|
||||
singletonMap(MatchAllQueryBuilder.NAME, new Tuple<>(MatchAllQueryParser.QUERY_NAME_FIELD, new MatchAllQueryParser())));
|
||||
Map<String, TransformFactory> factories = new HashMap<>();
|
||||
ChainTransformFactory parser = new ChainTransformFactory();
|
||||
factories.put(ChainTransform.TYPE, parser);
|
||||
|
|
Loading…
Reference in New Issue