Hi,

You need to set the size on the terms aggregation:

AggregationBuilders.terms("category_names").field("category").size(20)


On Mon, Jul 28, 2014 at 9:22 PM, Alain Désilets <[email protected]>
wrote:

> I have an ES where I have indexed a bunch of files. Each file is tagged
> with a category field. I want to write Java code to get a list of all the
> categories. I am trying to do this using the terms aggregation:
>
> QueryBuilder qb = QueryBuilders.matchAllQuery();
> SearchResponse sr =
> esClient.prepareSearch()
> .setQuery(qb)
> .setSize(20)
>
> .addAggregation(AggregationBuilders.terms("category_names").field("category")).setSize(20)
> .execute()
> .actionGet();
>
> Terms terms = sr.getAggregations().get("category_names");
> int numCategories = terms.getBuckets().size();
> System.out.println("Number of category buckets found: "+ numCategories);
>
> But this code always prints out that it found 10 category buckets. Yet, if
> I execute the following query in Sense:
>
> GET files-index/file_with_category/_search
> {
>   "query": {
>       "match_all": {}
>   },
>   "aggs": {
>     "categories": {
>       "terms": {
>         "field": "category",
>         "size": 100
>       }
>     }
>   }
> }
>
> I get 18 category buckets. What am I doing wrong in the Java code?
>
> Thx.
>
> Alain
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "elasticsearch" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/elasticsearch/b6d0300c-524e-423b-bd5a-6ce9d9e7b168%40googlegroups.com
> <https://groups.google.com/d/msgid/elasticsearch/b6d0300c-524e-423b-bd5a-6ce9d9e7b168%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>



-- 
Adrien Grand

-- 
You received this message because you are subscribed to the Google Groups 
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/CAL6Z4j5msVrWa1TGkAFs1J3fudTs3mpKEA%3DCQevSJPFcbObgRQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to