Search in sources :

Example 1 with TermsAggregationQuery

use of com.enonic.xp.query.aggregation.TermsAggregationQuery in project xp by enonic.

the class QueryAggregationParamsTest method testTermsAggregation.

@Test
public void testTermsAggregation() {
    final Map<String, Object> termsAggregation = new HashMap<>();
    termsAggregation.put("field", "fieldName");
    termsAggregation.put("order", "_count desc");
    termsAggregation.put("size", 10);
    termsAggregation.put("minDocCount", 5);
    final Map<String, Object> aggregations = new HashMap<>();
    aggregations.put("aggName", Collections.singletonMap("terms", termsAggregation));
    final AggregationQueries result = new QueryAggregationParams().getAggregations(aggregations);
    assertEquals(1, result.getSize());
    assertTrue(result.first() instanceof TermsAggregationQuery);
    final TermsAggregationQuery query = (TermsAggregationQuery) result.first();
    assertNotNull(query);
    assertEquals("fieldName", query.getFieldName());
    assertEquals(5, query.getMinDocCount());
}
Also used : TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) HashMap(java.util.HashMap) AggregationQueries(com.enonic.xp.query.aggregation.AggregationQueries) Test(org.junit.jupiter.api.Test)

Example 2 with TermsAggregationQuery

use of com.enonic.xp.query.aggregation.TermsAggregationQuery in project xp by enonic.

the class AggregationQueryBuilderFactory method doCreate.

private Set<AbstractAggregationBuilder> doCreate(final AggregationQueries aggregationQueries) {
    Set<AbstractAggregationBuilder> aggregationBuilders = new HashSet<>();
    for (final AggregationQuery aggregationQuery : aggregationQueries) {
        final AbstractAggregationBuilder aggregationBuilder;
        if (aggregationQuery instanceof TermsAggregationQuery) {
            aggregationBuilder = new TermsAggregationQueryBuilderFactory(fieldNameResolver).create((TermsAggregationQuery) aggregationQuery);
        } else if (aggregationQuery instanceof AbstractRangeAggregationQuery) {
            aggregationBuilder = new RangeAggregationQueryBuilderFactory(fieldNameResolver).create((AbstractRangeAggregationQuery) aggregationQuery);
        } else if (aggregationQuery instanceof AbstractHistogramAggregationQuery) {
            aggregationBuilder = new HistogramAggregationQueryBuilderFactory(fieldNameResolver).create((AbstractHistogramAggregationQuery) aggregationQuery);
        } else if (aggregationQuery instanceof MetricAggregationQuery) {
            aggregationBuilder = new MetricAggregationQueryBuilderFactory(fieldNameResolver).create((MetricAggregationQuery) aggregationQuery);
        } else {
            throw new IllegalArgumentException("Unexpected aggregation type: " + aggregationQuery.getClass());
        }
        handleSubAggregations(aggregationQuery, aggregationBuilder);
        aggregationBuilders.add(aggregationBuilder);
    }
    return aggregationBuilders;
}
Also used : AbstractRangeAggregationQuery(com.enonic.xp.query.aggregation.AbstractRangeAggregationQuery) AbstractHistogramAggregationQuery(com.enonic.xp.query.aggregation.AbstractHistogramAggregationQuery) MetricAggregationQuery(com.enonic.xp.query.aggregation.MetricAggregationQuery) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) BucketAggregationQuery(com.enonic.xp.query.aggregation.BucketAggregationQuery) AggregationQuery(com.enonic.xp.query.aggregation.AggregationQuery) MetricAggregationQuery(com.enonic.xp.query.aggregation.MetricAggregationQuery) AbstractAggregationBuilder(org.elasticsearch.search.aggregations.AbstractAggregationBuilder) TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) AbstractRangeAggregationQuery(com.enonic.xp.query.aggregation.AbstractRangeAggregationQuery) AbstractHistogramAggregationQuery(com.enonic.xp.query.aggregation.AbstractHistogramAggregationQuery) HashSet(java.util.HashSet)

Example 3 with TermsAggregationQuery

use of com.enonic.xp.query.aggregation.TermsAggregationQuery in project xp by enonic.

the class QueryAggregationParamsTest method testTermsAggregationWithoutMinDocCount.

@Test
public void testTermsAggregationWithoutMinDocCount() {
    final Map<String, Object> termsAggregation = new HashMap<>();
    termsAggregation.put("field", "fieldName");
    termsAggregation.put("order", "_count desc");
    termsAggregation.put("size", 10);
    final Map<String, Object> aggregations = new HashMap<>();
    aggregations.put("aggName", Collections.singletonMap("terms", termsAggregation));
    final AggregationQueries result = new QueryAggregationParams().getAggregations(aggregations);
    assertEquals(1, result.getSize());
    assertTrue(result.first() instanceof TermsAggregationQuery);
    final TermsAggregationQuery query = (TermsAggregationQuery) result.first();
    assertNotNull(query);
    assertEquals("fieldName", query.getFieldName());
    assertEquals(1, query.getMinDocCount());
}
Also used : TermsAggregationQuery(com.enonic.xp.query.aggregation.TermsAggregationQuery) HashMap(java.util.HashMap) AggregationQueries(com.enonic.xp.query.aggregation.AggregationQueries) Test(org.junit.jupiter.api.Test)

Aggregations

TermsAggregationQuery (com.enonic.xp.query.aggregation.TermsAggregationQuery)3 AggregationQueries (com.enonic.xp.query.aggregation.AggregationQueries)2 HashMap (java.util.HashMap)2 Test (org.junit.jupiter.api.Test)2 AbstractHistogramAggregationQuery (com.enonic.xp.query.aggregation.AbstractHistogramAggregationQuery)1 AbstractRangeAggregationQuery (com.enonic.xp.query.aggregation.AbstractRangeAggregationQuery)1 AggregationQuery (com.enonic.xp.query.aggregation.AggregationQuery)1 BucketAggregationQuery (com.enonic.xp.query.aggregation.BucketAggregationQuery)1 MetricAggregationQuery (com.enonic.xp.query.aggregation.MetricAggregationQuery)1 HashSet (java.util.HashSet)1 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)1