0

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);
Diksha
  • 406
  • 5
  • 20
  • Can you show the query you're using? – Val Sep 04 '18 at 05:20
  • yes @Val updated the post.. – Diksha Sep 04 '18 at 05:35
  • The error message `[size] must be greater than 0` only comes if you try to set the size of the terms aggregation to 0, otherwise on the query it should work perfectly fine. – Val Sep 04 '18 at 05:38
  • But the total hits for this query is 457 and it has only 10 hits, like in this example there is a link that shows total number of users and when clicked on the link above query is passed to get the details. So total users are 457 but the hits are 10 only i.e I get only 10 users on next page. – Diksha Sep 04 '18 at 05:47
  • Then you can change size to be greater than 457, the [maximum size](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-from-size.html) you can set is 10000. – Val Sep 04 '18 at 05:53
  • Yes I can do this but there are cases where I don't know what will be the total number of results then what will we do in that? – Diksha Sep 04 '18 at 05:56
  • if you have more than 10000 results it is unlikely that you will want to show them all anyway... – Val Sep 04 '18 at 06:00
  • So just for knowledge if I'm having total 300 entries and I set the size param to 10000, will this not affect the performance or any other drawback? – Diksha Sep 04 '18 at 06:17
  • Nope, not that I know of. Best is always to test and see how it performs on your own cluster – Val Sep 04 '18 at 06:17
  • Alright thanks for your help. – Diksha Sep 04 '18 at 06:22

0 Answers0