title: Terms aggregation on multiple fields in Elasticsearch
body: <p>I'm trying to get some counts from Elasticsearch. I have a query:</p>
  
  <pre><code>GET index/_search
  {
    "aggs": {
      "first-metadata": {
        "terms": {
          "field": "filters.metadata.first-metadata"
        }
      }
    }
  }
  </code></pre>
  
  <p>and as a response I'm getting something like that:</p>
  
  <pre><code>"aggregations": {
    "first-metadata": {
      "buckets": [
        {
          "key": 87000,
          "doc_count": 2
        },
        {
          "key": 100000,
          "doc_count": 1
        }
      ]
    }
  }
  </code></pre>
  
  <p>Everything is like I've expected. But the problem is that I have multiple metadata types: <code>first-metadata</code>, <code>second-metadata</code> and <code>third-metadata</code> and I would like to have something like that:</p>
  
  <pre><code>"aggregations": {
    "first-metadata": {
      "buckets": [
        {
          "key": 87000,
          "doc_count": 2
        },
        {
          "key": 100000,
          "doc_count": 1
        }
      ]
    },
    "second-metadata": {
      "buckets": [
        {
          "key": 5555,
          "doc_count": 24
        },
        {
          "key": 2222,
          "doc_count": 14
        },
        {
          "key": 3333,
          "doc_count": 7
        }
      ]
    },
    "third-metadata": {
      "buckets": [
        {
          "key": 7777,
          "doc_count": 23
        },
        {
          "key": 3333,
          "doc_count": 11
        }
      ]
    }
  }
  </code></pre>
  
  <p>Is there any way to achieve such results in one aggregation query?</p>