X-Plugin changes due to the changes in the Aggregations Java API

Original commit: elastic/x-pack-elasticsearch@b983d0a00f
This commit is contained in:
Colin Goodheart-Smithe 2016-02-10 14:13:10 +00:00
parent ec76d3bce0
commit 197b8fe56f
15 changed files with 49 additions and 37 deletions

View File

@ -170,7 +170,7 @@ public class IndexActionIntegrationTests extends AbstractWatcherIntegrationTestC
.source(searchSource()
.aggregation(dateHistogram("trend")
.field("timestamp")
.interval(DateHistogramInterval.DAY)))))
.dateHistogramInterval(DateHistogramInterval.DAY)))))
.addAction("index-buckets",
// this transform takes the bucket list and assigns it to `_doc`

View File

@ -72,7 +72,7 @@ public class ScriptConditionSearchTests extends AbstractWatcherIntegrationTestCa
SearchResponse response = client().prepareSearch("my-index")
.addAggregation(AggregationBuilders.dateHistogram("rate").field("_timestamp")
.interval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.dateHistogramInterval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.get();
ExecutableScriptCondition condition = new ExecutableScriptCondition(
@ -85,9 +85,8 @@ public class ScriptConditionSearchTests extends AbstractWatcherIntegrationTestCa
client().prepareIndex("my-index", "my-type").setTimestamp("2005-01-01T00:40").setSource("{}").get();
refresh();
response = client().prepareSearch("my-index")
.addAggregation(AggregationBuilders.dateHistogram("rate").field("_timestamp").interval(DateHistogramInterval.HOUR)
.order(Histogram.Order.COUNT_DESC))
response = client().prepareSearch("my-index").addAggregation(AggregationBuilders.dateHistogram("rate").field("_timestamp")
.dateHistogramInterval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.get();
ctx = mockExecutionContext("_name", new Payload.XContent(response));

View File

@ -8,7 +8,6 @@ package org.elasticsearch.messy.tests;
import org.elasticsearch.action.indexedscripts.put.PutIndexedScriptRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchType;
import org.elasticsearch.common.collect.HppcMaps;
import org.elasticsearch.common.io.Streams;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
@ -282,7 +281,7 @@ public class SearchInputTests extends ESIntegTestCase {
parser.nextToken();
IndicesQueriesRegistry indicesQueryRegistry = internalCluster().getInstance(IndicesQueriesRegistry.class);
SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, ClientProxy.of(client()), indicesQueryRegistry);
SearchInputFactory factory = new SearchInputFactory(Settings.EMPTY, ClientProxy.of(client()), indicesQueryRegistry, null);
SearchInput searchInput = factory.parseInput("_id", parser);
assertEquals(SearchInput.TYPE, searchInput.type());

View File

@ -319,7 +319,8 @@ public class SearchTransformTests extends ESIntegTestCase {
IndicesQueriesRegistry indicesQueryRegistry = internalCluster().getInstance(IndicesQueriesRegistry.class);
SearchTransformFactory transformFactory = new SearchTransformFactory(Settings.EMPTY, ClientProxy.of(client()),
indicesQueryRegistry);
indicesQueryRegistry,
null);
ExecutableSearchTransform executable = transformFactory.parseExecutable("_id", parser);
assertThat(executable, notNullValue());

View File

@ -347,7 +347,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
SearchResponse response = client().prepareSearch("test")
.setTypes("type1")
.addAggregation(AggregationBuilders.children("children").childType("type2")
.addAggregation(AggregationBuilders.children("children", "type2")
.subAggregation(AggregationBuilders.terms("field3").field("field3")))
.get();
assertHitCount(response, 1);
@ -362,7 +362,7 @@ public class DocumentLevelSecurityTests extends ShieldIntegTestCase {
response = client().filterWithHeader(Collections.singletonMap(BASIC_AUTH_HEADER, basicAuthHeaderValue("user1", USERS_PASSWD)))
.prepareSearch("test")
.setTypes("type1")
.addAggregation(AggregationBuilders.children("children").childType("type2")
.addAggregation(AggregationBuilders.children("children", "type2")
.subAggregation(AggregationBuilders.terms("field3").field("field3")))
.get();
assertHitCount(response, 1);

View File

@ -14,6 +14,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.watcher.input.Input;
import org.elasticsearch.watcher.support.SearchRequestEquivalence;
import org.elasticsearch.watcher.support.WatcherDateTimeUtils;
@ -110,7 +111,8 @@ public class SearchInput implements Input {
return builder;
}
public static SearchInput parse(String watchId, XContentParser parser, QueryParseContext context) throws IOException {
public static SearchInput parse(String watchId, XContentParser parser, QueryParseContext context, AggregatorParsers aggParsers)
throws IOException {
SearchRequest request = null;
Set<String> extract = null;
TimeValue timeout = null;
@ -123,7 +125,7 @@ public class SearchInput implements Input {
currentFieldName = parser.currentName();
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.REQUEST)) {
try {
request = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context);
request = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, aggParsers);
} catch (ElasticsearchParseException srpe) {
throw new ElasticsearchParseException("could not parse [{}] input for watch [{}]. failed to parse [{}]", srpe, TYPE,
watchId, currentFieldName);

View File

@ -12,6 +12,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.watcher.input.InputFactory;
import org.elasticsearch.watcher.input.simple.ExecutableSimpleInput;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
@ -26,12 +27,14 @@ public class SearchInputFactory extends InputFactory<SearchInput, SearchInput.Re
private final ClientProxy client;
private final TimeValue defaultTimeout;
private IndicesQueriesRegistry queryRegistry;
private AggregatorParsers aggParsers;
@Inject
public SearchInputFactory(Settings settings, ClientProxy client, IndicesQueriesRegistry queryRegistry) {
public SearchInputFactory(Settings settings, ClientProxy client, IndicesQueriesRegistry queryRegistry, AggregatorParsers aggParsers) {
super(Loggers.getLogger(ExecutableSimpleInput.class, settings));
this.client = client;
this.queryRegistry = queryRegistry;
this.aggParsers = aggParsers;
this.defaultTimeout = settings.getAsTime("watcher.input.search.default_timeout", null);
}
@ -44,7 +47,7 @@ public class SearchInputFactory extends InputFactory<SearchInput, SearchInput.Re
public SearchInput parseInput(String watchId, XContentParser parser) throws IOException {
QueryParseContext context = new QueryParseContext(queryRegistry);
context.reset(parser);
return SearchInput.parse(watchId, parser, context);
return SearchInput.parse(watchId, parser, context, aggParsers);
}
@Override

View File

@ -20,6 +20,7 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.script.ScriptService.ScriptType;
import org.elasticsearch.script.Template;
import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.elasticsearch.watcher.execution.WatchExecutionContext;
import org.elasticsearch.watcher.watch.Payload;
@ -99,7 +100,8 @@ public final class WatcherUtils {
/**
* Reads a new search request instance for the specified parser.
*/
public static SearchRequest readSearchRequest(XContentParser parser, SearchType searchType, QueryParseContext context)
public static SearchRequest readSearchRequest(XContentParser parser, SearchType searchType, QueryParseContext context,
AggregatorParsers aggParsers)
throws IOException {
IndicesOptions indicesOptions = DEFAULT_INDICES_OPTIONS;
SearchRequest searchRequest = new SearchRequest();
@ -110,7 +112,7 @@ public final class WatcherUtils {
if (token == XContentParser.Token.FIELD_NAME) {
currentFieldName = parser.currentName();
if (ParseFieldMatcher.STRICT.match(currentFieldName, BODY_FIELD)) {
searchRequest.source(SearchSourceBuilder.parseSearchSource(parser, context));
searchRequest.source(SearchSourceBuilder.parseSearchSource(parser, context, aggParsers));
}
} else if (token == XContentParser.Token.START_ARRAY) {
if (ParseFieldMatcher.STRICT.match(currentFieldName, INDICES_FIELD)) {

View File

@ -14,6 +14,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.watcher.support.SearchRequestEquivalence;
import org.elasticsearch.watcher.support.WatcherDateTimeUtils;
import org.elasticsearch.watcher.support.WatcherUtils;
@ -92,7 +93,8 @@ public class SearchTransform implements Transform {
return builder;
}
public static SearchTransform parse(String watchId, XContentParser parser, QueryParseContext context) throws IOException {
public static SearchTransform parse(String watchId, XContentParser parser, QueryParseContext context, AggregatorParsers aggParsers)
throws IOException {
SearchRequest request = null;
TimeValue timeout = null;
DateTimeZone dynamicNameTimeZone = null;
@ -104,7 +106,7 @@ public class SearchTransform implements Transform {
currentFieldName = parser.currentName();
} else if (ParseFieldMatcher.STRICT.match(currentFieldName, Field.REQUEST)) {
try {
request = WatcherUtils.readSearchRequest(parser, ExecutableSearchTransform.DEFAULT_SEARCH_TYPE, context);
request = WatcherUtils.readSearchRequest(parser, ExecutableSearchTransform.DEFAULT_SEARCH_TYPE, context, aggParsers);
} catch (ElasticsearchParseException srpe) {
throw new ElasticsearchParseException("could not parse [{}] transform for watch [{}]. failed to parse [{}]", srpe,
TYPE, watchId, currentFieldName);

View File

@ -12,6 +12,7 @@ import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.aggregations.AggregatorParsers;
import org.elasticsearch.watcher.support.init.proxy.ClientProxy;
import org.elasticsearch.watcher.transform.TransformFactory;
@ -25,12 +26,15 @@ public class SearchTransformFactory extends TransformFactory<SearchTransform, Se
protected final ClientProxy client;
private final TimeValue defaultTimeout;
private IndicesQueriesRegistry queryRegistry;
private AggregatorParsers aggParsers;
@Inject
public SearchTransformFactory(Settings settings, ClientProxy client, IndicesQueriesRegistry queryRegistry) {
public SearchTransformFactory(Settings settings, ClientProxy client, IndicesQueriesRegistry queryRegistry,
AggregatorParsers aggParsers) {
super(Loggers.getLogger(ExecutableSearchTransform.class, settings));
this.client = client;
this.queryRegistry = queryRegistry;
this.aggParsers = aggParsers;
this.defaultTimeout = settings.getAsTime("watcher.transform.search.default_timeout", null);
}
@ -43,7 +47,7 @@ public class SearchTransformFactory extends TransformFactory<SearchTransform, Se
public SearchTransform parseTransform(String watchId, XContentParser parser) throws IOException {
QueryParseContext context = new QueryParseContext(queryRegistry);
context.reset(parser);
return SearchTransform.parse(watchId, parser, context);
return SearchTransform.parse(watchId, parser, context, aggParsers);
}
@Override

View File

@ -160,7 +160,7 @@ public class IndexActionIntegrationTests extends AbstractWatcherIntegrationTestC
.source(searchSource()
.aggregation(dateHistogram("trend")
.field("timestamp")
.interval(DateHistogramInterval.DAY)))))
.dateHistogramInterval(DateHistogramInterval.DAY)))))
.addAction("index-buckets",
// this transform takes the bucket list and assigns it to `_doc`

View File

@ -51,7 +51,7 @@ public class CompareConditionSearchTests extends AbstractWatcherIntegrationTestC
SearchResponse response = client().prepareSearch("my-index")
.addAggregation(AggregationBuilders.dateHistogram("rate").field("_timestamp")
.interval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.dateHistogramInterval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.get();
ExecutableCompareCondition condition = new ExecutableCompareCondition(
@ -70,7 +70,7 @@ public class CompareConditionSearchTests extends AbstractWatcherIntegrationTestC
response = client().prepareSearch("my-index")
.addAggregation(AggregationBuilders.dateHistogram("rate")
.field("_timestamp").interval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.field("_timestamp").dateHistogramInterval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.get();
ctx = mockExecutionContext("_name", new Payload.XContent(response));

View File

@ -62,7 +62,7 @@ public class ScriptConditionSearchTests extends AbstractWatcherIntegrationTestCa
SearchResponse response = client().prepareSearch("my-index")
.addAggregation(AggregationBuilders.dateHistogram("rate")
.field("_timestamp").interval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.field("_timestamp").dateHistogramInterval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.get();
ExecutableScriptCondition condition = new ExecutableScriptCondition(
@ -77,7 +77,7 @@ public class ScriptConditionSearchTests extends AbstractWatcherIntegrationTestCa
response = client().prepareSearch("my-index")
.addAggregation(AggregationBuilders.dateHistogram("rate")
.field("_timestamp").interval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.field("_timestamp").dateHistogramInterval(DateHistogramInterval.HOUR).order(Histogram.Order.COUNT_DESC))
.get();
ctx = mockExecutionContext("_name", new Payload.XContent(response));

View File

@ -136,7 +136,7 @@ public class WatcherUtilsTests extends ESTestCase {
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, singletonMap("match_all", new MatchAllQueryParser()));
QueryParseContext context = new QueryParseContext(registry);
context.reset(parser);
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context);
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null);
assertThat(result.indices(), arrayContainingInAnyOrder(expectedRequest.indices()));
assertThat(result.types(), arrayContainingInAnyOrder(expectedRequest.types()));
@ -224,7 +224,7 @@ public class WatcherUtilsTests extends ESTestCase {
IndicesQueriesRegistry registry = new IndicesQueriesRegistry(Settings.EMPTY, singletonMap("match_all", new MatchAllQueryParser()));
QueryParseContext context = new QueryParseContext(registry);
context.reset(parser);
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context);
SearchRequest result = WatcherUtils.readSearchRequest(parser, ExecutableSearchInput.DEFAULT_SEARCH_TYPE, context, null);
assertThat(result.indices(), arrayContainingInAnyOrder(indices));
assertThat(result.types(), arrayContainingInAnyOrder(types));

View File

@ -350,10 +350,10 @@ 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()));
parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, queryRegistry));
return new InputRegistry(parsers);
IndicesQueriesRegistry queryRegistry = new IndicesQueriesRegistry(Settings.EMPTY,
singletonMap("match_all", new MatchAllQueryParser()));
parsers.put(SearchInput.TYPE, new SearchInputFactory(settings, client, queryRegistry, null));
return new InputRegistry(parsers);
default:
parsers.put(SimpleInput.TYPE, new SimpleInputFactory(settings));
return new InputRegistry(parsers);
@ -423,7 +423,7 @@ public class WatchTests extends ESTestCase {
ChainTransformFactory parser = new ChainTransformFactory();
factories.put(ChainTransform.TYPE, parser);
factories.put(ScriptTransform.TYPE, new ScriptTransformFactory(settings, scriptService));
factories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, client, queryRegistry));
factories.put(SearchTransform.TYPE, new SearchTransformFactory(settings, client, queryRegistry, null));
TransformRegistry registry = new TransformRegistry(unmodifiableMap(factories));
parser.init(registry);
return registry;