title: ElasticsearchTemplate retrieve big data sets
body: <p>I am new to ElasticsearchTemplate. I want to get 1000 documents from Elasticsearch based on my query.
  I have used QueryBuilder to create my query , and it is working perfectly.
  I have gone through the following links , which states that it is possible to achieve big data sets using scan and scroll.<br><br>
  <a href="https://stackoverflow.com/questions/29080251/spring-data-elasticsearch-scan-and-scroll-paged-result-is-not-working">link one</a><br>
  <a href="https://docs.spring.io/spring-data/elasticsearch/docs/1.0.0.M1/reference/html/elasticsearch.misc.html" rel="nofollow noreferrer">link two</a></p>
  
  <p>I am trying to implement this functionality in the following section of code, which I have copy pasted from one of the link , mentioned above.
  But I am getting following error :</p>
  
  <p><code>The type ResultsMapper is not generic; it cannot be parameterized with arguments &lt;myInputDto&gt;.</code></p>
  
  <p><code>MyInputDto</code> is a class with <code>@Document</code> annotation in my project.
  End of the day , I just want to retrieve 1000 documents from Elasticsearch. 
  I tried to find <code>size</code> parameter but I think it is not supported.</p>
  
  <pre><code>String scrollId = esTemplate.scan(searchQuery, 1000, false);
          List&lt;MyInputDto&gt; sampleEntities = new ArrayList&lt;MyInputDto&gt;();
          boolean hasRecords = true;
          while (hasRecords) {
              Page&lt;MyInputDto&gt; page = esTemplate.scroll(scrollId, 5000L,
                      new ResultsMapper&lt;MyInputDto&gt;() {
                          @Override
                          public Page&lt;MyInputDto&gt; mapResults(SearchResponse response) {
                              List&lt;MyInputDto&gt; chunk = new ArrayList&lt;MyInputDto&gt;();
                              for (SearchHit searchHit : response.getHits()) {
                                  if (response.getHits().getHits().length &lt;= 0) {
                                      return null;
                                  }
                                  MyInputDto user = new MyInputDto();
                                  user.setId(searchHit.getId());
                                  user.setMessage((String) searchHit.getSource().get("message"));
                                  chunk.add(user);
                              }
                              return new PageImpl&lt;MyInputDto&gt;(chunk);
                          }
                      });
              if (page != null) {
                  sampleEntities.addAll(page.getContent());
                  hasRecords = page.hasNextPage();
              } else {
                  hasRecords = false;
              }
          }
  </code></pre>
  
  <p>What is the issue here ?
  Is there any other alternative to achieve this?
  I will be thankful if somebody could tell me how this ( code ) is working in the back end.</p>