use of org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder in project sonarqube by SonarSource.
the class ProjectMeasuresIndex method createQualityGateFacet.
private static AbstractAggregationBuilder createQualityGateFacet() {
FiltersAggregationBuilder qualityGateStatusFilter = AggregationBuilders.filters(ALERT_STATUS_KEY);
QUALITY_GATE_STATUS.entrySet().forEach(entry -> qualityGateStatusFilter.filter(entry.getKey(), termQuery(FIELD_QUALITY_GATE_STATUS, entry.getValue())));
return qualityGateStatusFilter;
}
use of org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder in project elasticsearch by elastic.
the class FiltersTests method testFiltersSortedByKey.
/**
* Test that when passing in keyed filters as list or array, the list stored internally is sorted by key
* Also check the list passed in is not modified by this but rather copied
*/
public void testFiltersSortedByKey() {
KeyedFilter[] original = new KeyedFilter[] { new KeyedFilter("bbb", new MatchNoneQueryBuilder()), new KeyedFilter("aaa", new MatchNoneQueryBuilder()) };
FiltersAggregationBuilder builder;
builder = new FiltersAggregationBuilder("my-agg", original);
assertEquals("aaa", builder.filters().get(0).key());
assertEquals("bbb", builder.filters().get(1).key());
// original should be unchanged
assertEquals("bbb", original[0].key());
assertEquals("aaa", original[1].key());
}
use of org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder in project elasticsearch by elastic.
the class FiltersTests method createTestAggregatorBuilder.
@Override
protected FiltersAggregationBuilder createTestAggregatorBuilder() {
int size = randomIntBetween(1, 20);
FiltersAggregationBuilder factory;
if (randomBoolean()) {
KeyedFilter[] filters = new KeyedFilter[size];
int i = 0;
for (String key : randomUnique(() -> randomAsciiOfLengthBetween(1, 20), size)) {
filters[i++] = new KeyedFilter(key, QueryBuilders.termQuery(randomAsciiOfLengthBetween(5, 20), randomAsciiOfLengthBetween(5, 20)));
}
factory = new FiltersAggregationBuilder(randomAsciiOfLengthBetween(1, 20), filters);
} else {
QueryBuilder[] filters = new QueryBuilder[size];
for (int i = 0; i < size; i++) {
filters[i] = QueryBuilders.termQuery(randomAsciiOfLengthBetween(5, 20), randomAsciiOfLengthBetween(5, 20));
}
factory = new FiltersAggregationBuilder(randomAsciiOfLengthBetween(1, 20), filters);
}
if (randomBoolean()) {
factory.otherBucket(randomBoolean());
}
if (randomBoolean()) {
factory.otherBucketKey(randomAsciiOfLengthBetween(1, 20));
}
return factory;
}
use of org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder in project elasticsearch by elastic.
the class FiltersAggregatorTests method testEmpty.
public void testEmpty() throws Exception {
Directory directory = newDirectory();
RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory);
indexWriter.close();
IndexReader indexReader = DirectoryReader.open(directory);
IndexSearcher indexSearcher = newSearcher(indexReader, true, true);
int numFilters = randomIntBetween(1, 10);
QueryBuilder[] filters = new QueryBuilder[numFilters];
for (int i = 0; i < filters.length; i++) {
filters[i] = QueryBuilders.termQuery("field", randomAsciiOfLength(5));
}
FiltersAggregationBuilder builder = new FiltersAggregationBuilder("test", filters);
builder.otherBucketKey("other");
InternalFilters response = search(indexSearcher, new MatchAllDocsQuery(), builder, fieldType);
assertEquals(response.getBuckets().size(), numFilters);
for (InternalFilters.InternalBucket filter : response.getBuckets()) {
assertEquals(filter.getDocCount(), 0);
}
indexReader.close();
directory.close();
}
use of org.elasticsearch.search.aggregations.bucket.filters.FiltersAggregationBuilder in project sonarqube by SonarSource.
the class ComponentIndex method createAggregation.
private static FiltersAggregationBuilder createAggregation(ComponentIndexQuery query) {
FiltersAggregationBuilder filtersAggregation = AggregationBuilders.filters(FILTERS_AGGREGATION_NAME).subAggregation(createSubAggregation(query));
query.getQualifiers().forEach(q -> filtersAggregation.filter(q, termQuery(FIELD_QUALIFIER, q)));
return filtersAggregation;
}
Aggregations