title: Getting count and list of ids using ElasticsearchTemplate in spring-data-elasticsearch
body: <p>I am using spring-data-elasticsearch for a project to provide it with full text search functionality. We keep the real data in a relational database and relevant metadata along with respective id in elasticsearch. So for search results, only id field is required as the actual data will be retrieved from the relational database.</p>
  
  <p>I am building the search query based on search criteria and then performing a queryForIds():    </p>
  
  <pre><code>    SearchQuery searchQuery = new NativeSearchQueryBuilder()
              .withIndices(indexName)
              .withTypes(typeName)
              .withQuery(getQueryBuilder(searchParams))
              .withPageable(pageable)
              .build();
  
      return elasticsearchTemplate.queryForIds(searchQuery);
  </code></pre>
  
  <p>If I also need the total count for that specific searchQuery, I can do another <code>elasticsearchTemplate.count(searchQuery)</code> call, but that will be redundant as I understand. I think there is a way to get both the list of id and total count by using something like <code>elasticsearchTemplate.queryForPage()</code> in a single call.</p>
  
  <p>Also, can I use a custom class in <code>queryForPage(SearchQuery query, Class&lt;T&gt; clazz, SearchResultMapper mapper)</code> which is not annotated with <code>@Document</code>? The actual document class is really big, and if I am not sure if passing large classes will cause any extra load on the engine since there are over 100 fields to be json mapped, but all I need is the id field. I will have a <code>.withFields("id")</code> in the query builder anyway.</p>