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.
For more options, visit https://groups.google.com/d/optout.