how does ElasticSearch set the filtering in a group query
<p>In this official site
<a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/_executing_aggregations.html" rel="nofollow">https://www.elastic.co/guide/en/elasticsearch/reference/current/_executing_aggregations.html</a></p>

<p>they have this query:</p>

<pre><code>curl -XPOST 'localhost:9200/bank/_search?pretty' -d '
{
  "size": 0,
  "aggs": {
    "group_by_state": {
      "terms": {
        "field": "state"
      }
    }
  }
}'
</code></pre>

<p>and then say it is similar to :</p>

<pre><code>SELECT state, COUNT(*) FROM bank GROUP BY state ORDER BY COUNT(*) DESC
</code></pre>

<p>my question is where is the mapping?</p>

<p>is it that when selecting the properties inside the <code>terms</code> part, that means the <code>select state, count(*)</code> ?</p>

<p>and where is the code in that elasticsearch query that is states to order desc?</p>