Question

I am using Elastic Search and aggregation as request on my documents. My aggregation is a terms aggregation on a specific field.

I would like to be able to get all the aggregations but the request only return me the 10th first. I tried to use the scroll of elastic search, but it is applied at the request and not on the aggregation, the documents returned are well scrolled, but the aggregation are still the same.

Does anyone had the same issue ?

Here is my request in java :

SearchResponse response = client.prepareSearch("index").setTypes("type").setQuery(QueryBuilders.matchAllQuery())
                .addAggregation(AggregationBuilders.terms("TermsAggr").field("aggField")).execute().actionGet();

And here is how i am getting the buckets :

    Terms terms = response.getAggregations().get("TermsAggr");
    Collection<Bucket> buckets = terms.getBuckets();
Was it helpful?

Solution

The default return size for an aggregation result is 10 items, that is why you are only getting 10 results back. You will need to set the size on the AggregationBuilders object to a larger value in order to return more or all values in the bucket.

 SearchResponse response = client.prepareSearch("index")
      .setTypes("type")
      .setQuery(QueryBuilders.matchAllQuery())
      .addAggregation(AggregationBuilders.terms("TermsAggr")
           .field("aggField").size(100))
      .execute().actionGet();

If you always want to return all values, you can set size(0). However, you will need to upgrade to ES 1.1, as this was recently added to that release via Issue 4837.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top