title: Elastic search 6.2 alternative for size[0] param of previous versions
body: <p>In the previous versions of ES when we didn't know the expected size of result of a specific query with aggregation we passed <code>size: 0</code>. But in ES 6.2.x versions, the param <code>size</code> cannot be set to 0(zero), it throws the following exception:<br></p>
  
  <pre><code>java.lang.IllegalArgumentException: [size] must be greater than 0.
  </code></pre>
  
  <p>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 <a href="https://www.elastic.co/guide/en/elasticsearch/client/java-api/6.2/java-search-scrolling.html" rel="nofollow noreferrer">scroll</a> and this <a href="https://stackoverflow.com/a/32747910">solution at SO</a>. I've tried the scroll option but I think I've been doing something wrong that I'm getting the following exception:<br></p>
  
  <pre><code>org.elasticsearch.search.SearchContextMissingException: No search context found for id [1578]
  </code></pre>
  
  <p>And I don't know how to do the second option in java. Any help will be great. Thanks.</p>
  
  <p><strong>EDIT</strong><br>
  Query that I'm currently using, as size param is not set it returns only 10 results:</p>
  
  <pre><code>    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);
  </code></pre>