In the previous versions of ES when we didn't know the expected size of result of a specific query with aggregation we passed size: 0
. But in ES 6.2.x versions, the param size
cannot be set to 0(zero), it throws the following exception:
java.lang.IllegalArgumentException: [size] must be greater than 0.
So what's the alternate way of doing it. I'm a beginner in ES. I've done some searching on net and found to do it using scroll and this solution at SO. I've tried the scroll option but I think I've been doing something wrong that I'm getting the following exception:
org.elasticsearch.search.SearchContextMissingException: No search context found for id [1578]
And I don't know how to do the second option in java. Any help will be great. Thanks.
EDIT
Query that I'm currently using, as size param is not set it returns only 10 results:
QueryBuilder qb= QueryBuilders
.boolQuery()
.must(termQuery("Key", Val));
SearchRequestBuilder requestBuilder = client.prepareSearch()
.setIndices()
.setTypes(getType())
.setScroll(new TimeValue(ES_TIMEOUT_MS))
.setQuery(qb);
//requestBuilder.setFrom(0);
// requestBuilder.setSize(0);
requestBuilder.addAggregation((terms("name").field("name"))
.subAggregation(topHits("top").size(1).fetchSource(new String[]{ "name","numPosts", "timeCreated", "timeLastActivity", "Key", "indexVersion"},null)));
SearchResponse response = requestBuilder.execute().actionGet(ES_TIMEOUT_MS);