title: elasticsearch aggregation - exact count for bucket
body: <p>Elasticsearch newbie question.  I loaded shakespeare.json into Elastic, and I'm trying to figure out how to do an aggregation analogous to <code>select speaker, count(1) from line group by speaker</code>.  ("Line" is the type of document, and "speaker" is one of the properties.)</p>
  
  <p>Now I have a query like this:</p>
  
  <pre><code>{
    "size": 0,
    "query": {
      "query": {
        "match": {
          "play_name": "HAMLET"
        }
      }
    },
    "aggs": {
      "line_count": {
        "terms": {
          "field": "speaker.speaker_raw"
        }
      }
    }
  }
  </code></pre>
  
  <p>The results look right, but the ElasticSearch docs specify that document counts for the terms aggregation are approximate (<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html" rel="nofollow noreferrer">https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html</a>).  Is there some other magic to get exact counts within a bucket?  </p>
  
  <p>Separately, I already figured out that I had to pre-define a field on the index to have an un-analyzed version of "speaker" to ensure I can aggregate on the original field values, not tokenized.  (See <a href="https://stackoverflow.com/questions/37337428/elasticsearch-cardinality-over-full-field-value">Elasticsearch - Cardinality over Full Field Value</a>) </p>