FiltersAggregatorBuilder: Don't create new context for inner parsing

We don't have to create new parse context for inner parsing.
This commit is contained in:
Christoph Büscher 2016-04-19 12:57:38 +02:00
parent 102a398d9f
commit bbe03c92c2
2 changed files with 13 additions and 18 deletions

View File

@ -478,7 +478,7 @@ public class SearchModule extends AbstractModule {
registerAggregation(GlobalAggregatorBuilder::new, GlobalAggregatorBuilder::parse, GlobalAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(MissingAggregatorBuilder::new, new MissingParser(), MissingAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(FilterAggregatorBuilder::new, FilterAggregatorBuilder::parse, FilterAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(FiltersAggregatorBuilder::new, (n, c) -> FiltersAggregatorBuilder.parse(queryParserRegistry, n, c),
registerAggregation(FiltersAggregatorBuilder::new, FiltersAggregatorBuilder::parse,
FiltersAggregatorBuilder.AGGREGATION_NAME_FIELD);
registerAggregation(SamplerAggregatorBuilder::new, SamplerAggregatorBuilder::parse,
SamplerAggregatorBuilder.AGGREGATION_NAME_FIELD);

View File

@ -19,15 +19,6 @@
package org.elasticsearch.search.aggregations.bucket.filters;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.elasticsearch.common.ParseField;
import org.elasticsearch.common.ParsingException;
import org.elasticsearch.common.io.stream.StreamInput;
@ -37,13 +28,21 @@ import org.elasticsearch.common.xcontent.XContentParser;
import org.elasticsearch.index.query.QueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.QueryParseContext;
import org.elasticsearch.indices.query.IndicesQueriesRegistry;
import org.elasticsearch.search.aggregations.AggregatorBuilder;
import org.elasticsearch.search.aggregations.AggregatorFactories.Builder;
import org.elasticsearch.search.aggregations.AggregatorFactory;
import org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregator.KeyedFilter;
import org.elasticsearch.search.aggregations.support.AggregationContext;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery;
public class FiltersAggregatorBuilder extends AggregatorBuilder<FiltersAggregatorBuilder> {
public static final String NAME = InternalFilters.TYPE.name();
public static final ParseField AGGREGATION_NAME_FIELD = new ParseField(NAME);
@ -205,7 +204,7 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder<FiltersAggregato
return builder;
}
public static FiltersAggregatorBuilder parse(IndicesQueriesRegistry queriesRegistry, String aggregationName, QueryParseContext context)
public static FiltersAggregatorBuilder parse(String aggregationName, QueryParseContext context)
throws IOException {
XContentParser parser = context.parser();
@ -241,9 +240,7 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder<FiltersAggregato
if (token == XContentParser.Token.FIELD_NAME) {
key = parser.currentName();
} else {
QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry, parser,
context.getParseFieldMatcher());
QueryBuilder<?> filter = queryParseContext.parseInnerQueryBuilder();
QueryBuilder<?> filter = context.parseInnerQueryBuilder();
keyedFilters.add(new FiltersAggregator.KeyedFilter(key, filter == null ? matchAllQuery() : filter));
}
}
@ -255,9 +252,7 @@ public class FiltersAggregatorBuilder extends AggregatorBuilder<FiltersAggregato
if (context.getParseFieldMatcher().match(currentFieldName, FILTERS_FIELD)) {
nonKeyedFilters = new ArrayList<>();
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
QueryParseContext queryParseContext = new QueryParseContext(queriesRegistry, parser,
context.getParseFieldMatcher());
QueryBuilder<?> filter = queryParseContext.parseInnerQueryBuilder();
QueryBuilder<?> filter = context.parseInnerQueryBuilder();
nonKeyedFilters.add(filter == null ? QueryBuilders.matchAllQuery() : filter);
}
} else {