title: Get Aggregate Information from Elasticsearch using Spring-data-elasticsearch, ElasticsearchRepository
body: <p>I would like to get aggregate results from ES like <code>avgSize</code> (avg of a field with name 'size'), <code>totalhits</code> for documents that match a term, and some other aggregates in future, for which I don't think <code>ElasticsearchRepository</code> has any methods to call. I built Query and Aggregate Builders as below. I want to use my Repository interface but I am not sure of what should the return ObjectType be ? Should it be a document type in my DTOs ? Also I have seen examples where the <code>searchQuery</code>is passed directly to <code>ElasticsearchTemplate</code> but then what is the point of having Repository interface that extends <code>ElasticsearchRepository</code></p>
  
  <p><code>Repository Interface</code></p>
  
  <pre><code>public interface CCFilesSummaryRepository extends ElasticsearchRepository&lt;DataReferenceSummary, UUID&gt; {
  
  }
  </code></pre>
  
  <p><code>Elastic configuration</code></p>
  
  <pre><code>@Configuration
  @EnableElasticsearchRepositories(basePackages = "com.xxx.repository.es")
  public class ElasticConfiguration {
      @Bean
      public ElasticsearchOperations elasticsearchTemplate() throws UnknownHostException {
          return new ElasticsearchTemplate(elasticsearchClient());
      }
      @Bean
      public Client elasticsearchClient() throws UnknownHostException {
          Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
          TransportClient client = new PreBuiltTransportClient(settings);
          client.addTransportAddress(new TransportAddress(InetAddress.getLocalHost(), 9200));
          return client;
      }
  }
  </code></pre>
  
  <p><code>Service Method</code></p>
  
  <pre><code>  public DataReferenceSummary createSummary(final DataSet dataSet) {
      try {
  
  
        QueryBuilder queryBuilder = QueryBuilders.matchQuery("type" , dataSet.getDataSetCreateRequest().getContentType());
        AvgAggregationBuilder avgAggregationBuilder =  AggregationBuilders.avg("avg_size").field("size");
        ValueCountAggregationBuilder valueCountAggregationBuilder = AggregationBuilders.count("total_references")
                .field("asset_id");
  
        SearchQuery searchQuery = new NativeSearchQueryBuilder()
                .withQuery(queryBuilder)
                .addAggregation(avgAggregationBuilder)
                .addAggregation(valueCountAggregationBuilder)
                .build();
  
  
        return ccFilesSummaryRepository.search(searchQuery).iterator().next();
  
  
      } catch (Exception e){
        e.printStackTrace();
      }
      return null;
  
    }
  </code></pre>
  
  <p><strong><code>DataReferernceSummary</code> is just a POJO for now and for which I am getting an error during my build that says <code>Unable to build Bean CCFilesSummaryRepository, illegalArgumentException DataReferernceSummary. is not a amanged Object</code></strong> </p>