title: ElasticSearch - get all available filters (aggregate) from index
body: <p>Let's say I have:</p>
  
  <pre><code>"hits": [
        {
          "_index": "products",
          "_type": "product",
          "_id": "599c2b3fc991ee0a597034fa",
          "_score": 1,
          "_source": {,
            "attributes": {
              "1": [
                "a"
              ],
              "2": [
                "b",
                "c"
              ],
              "3": [
                "d",
                "e"
              ],
              "4": [
                "f",
                "g"
              ],
              "5": [
                "h",
                "i"
              ]
            }
          }
        },
        {
          "_index": "products",
          "_type": "product",
          "_id": "599c4bb4b970c25976ced8bd",
          "_score": 1,
          "_source": {
            "attributes": {
              "1": [
                "z"
              ],
              "2": [
                "y"
              ]
            }
          }
  </code></pre>
  
  <p>Each product has attributes. Each attribute has ID and a value. I can filter the products by attributes fine but for now I am creating the "possible attributes" list from MongoDB. I would like to find a way to generate such a list from ElasticSearch alone (and maybe just query MongoDB for additional data).</p>
  
  <p>What I need is:</p>
  
  <pre><code>{
    1: [a, z],
    2: [b, c, y],
    etc.
  }
  </code></pre>
  
  <p>How would such a aggregation look like? Get all available attributes (grouped by <code>attribute.id</code>) with all of their possible values (throughout all products)?</p>