Search in sources :

Example 1 with KeyedFilter

use of org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter in project elasticsearch by elastic.

the class AdjacencyMatrixAggregationBuilder method doBuild.

@Override
protected AggregatorFactory<?> doBuild(SearchContext context, AggregatorFactory<?> parent, Builder subFactoriesBuilder) throws IOException {
    int maxFilters = context.indexShard().indexSettings().getMaxAdjacencyMatrixFilters();
    if (filters.size() > maxFilters) {
        throw new QueryPhaseExecutionException(context, "Number of filters is too large, must be less than or equal to: [" + maxFilters + "] but was [" + filters.size() + "]." + "This limit can be set by changing the [" + IndexSettings.MAX_ADJACENCY_MATRIX_FILTERS_SETTING.getKey() + "] index level setting.");
    }
    List<KeyedFilter> rewrittenFilters = new ArrayList<>();
    for (KeyedFilter kf : filters) {
        rewrittenFilters.add(new KeyedFilter(kf.key(), QueryBuilder.rewriteQuery(kf.filter(), context.getQueryShardContext())));
    }
    return new AdjacencyMatrixAggregatorFactory(name, rewrittenFilters, separator, context, parent, subFactoriesBuilder, metaData);
}
Also used : KeyedFilter(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter) QueryPhaseExecutionException(org.elasticsearch.search.query.QueryPhaseExecutionException) ArrayList(java.util.ArrayList)

Example 2 with KeyedFilter

use of org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter in project elasticsearch by elastic.

the class AdjacencyMatrixAggregationBuilder method internalXContent.

@Override
protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {
    builder.startObject();
    builder.field(SEPARATOR_FIELD.getPreferredName(), separator);
    builder.startObject(AdjacencyMatrixAggregator.FILTERS_FIELD.getPreferredName());
    for (KeyedFilter keyedFilter : filters) {
        builder.field(keyedFilter.key(), keyedFilter.filter());
    }
    builder.endObject();
    builder.endObject();
    return builder;
}
Also used : KeyedFilter(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter)

Example 3 with KeyedFilter

use of org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter in project elasticsearch by elastic.

the class AdjacencyMatrixAggregationBuilder method doWriteTo.

@Override
protected void doWriteTo(StreamOutput out) throws IOException {
    out.writeVInt(filters.size());
    out.writeString(separator);
    for (KeyedFilter keyedFilter : filters) {
        keyedFilter.writeTo(out);
    }
}
Also used : KeyedFilter(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter)

Example 4 with KeyedFilter

use of org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter in project elasticsearch by elastic.

the class AdjacencyMatrixAggregationBuilder method setFiltersAsMap.

protected void setFiltersAsMap(Map<String, QueryBuilder> filters) {
    // Convert uniquely named objects into internal KeyedFilters
    this.filters = new ArrayList<>(filters.size());
    for (Entry<String, QueryBuilder> kv : filters.entrySet()) {
        this.filters.add(new KeyedFilter(kv.getKey(), kv.getValue()));
    }
    // internally we want to have a fixed order of filters, regardless of
    // the order of the filters in the request
    Collections.sort(this.filters, Comparator.comparing(KeyedFilter::key));
}
Also used : KeyedFilter(org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter) QueryBuilder(org.elasticsearch.index.query.QueryBuilder)

Aggregations

KeyedFilter (org.elasticsearch.search.aggregations.bucket.adjacency.AdjacencyMatrixAggregator.KeyedFilter)4 ArrayList (java.util.ArrayList)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 QueryPhaseExecutionException (org.elasticsearch.search.query.QueryPhaseExecutionException)1