title: How to count Elastic Search documents based on multiple field values with the Java API?
body: <p>I am attempting to count the number of documents of a specific type based on the value of 2 of the documents fields.</p>
  
  <p>So far I can count the number of documents using:</p>
  
  <pre><code>SearchResponse response = elasticClient.getClient().prepareSearch(Properties.get().getSearch().getAliasName())
          .setTypes(type)
          .setSize(0) // Don't return any documents, we don't need them.
          .get();
  
  SearchHits hits = response.getHits();
  return (int) hits.getTotalHits();
  </code></pre>
  
  <p>Which returns the correct number of total documents.</p>
  
  <p>I can also search for a specific document using:</p>
  
  <pre><code>    searchResponse = elasticClient.getClient()
              .prepareSearch(index)
              .setSearchType(SearchType.QUERY_THEN_FETCH)
              .setQuery(QueryBuilders.prefixQuery(field_name, field_value))
              .setFetchSource(true)
              .setSize(10000)
              .setTypes(type)
              .addSort(builder.order(SortOrder.DESC))
              .get();
  </code></pre>
  
  <p>This also returns documents.</p>
  
  <p>I have attempted to count based on 2 field values using:</p>
  
  <pre><code>BoolQueryBuilder queryBuilder = QueryBuilders.boolQuery();
  queryBuilder.must(QueryBuilders.prefixQuery(field_1, value_1));
  queryBuilder.must(QueryBuilders.prefixQuery(field_2, value_2));
  SearchRequestBuilder searchBuilder = elasticClient.getClient().prepareSearch(index)
          .setQuery(queryBuilder)
          .setTypes(type)
          .setSize(0);
  </code></pre>
  
  <p>But this always returns 0.</p>
  
  <p>How do I correctly count documents based on 2 field values using the Java API?</p>