title: Terms Aggregation for nested field in Elastic Search
body: <p>I have next mapping for field in Elastic Search (definition in YML):</p>
  
  <pre><code>              my_analyzer:
                    type: custom
                    tokenizer:  keyword
                    filter: lowercase
  
                 products_filter:
                      type: "nested"
                      properties:
                          filter_name: {"type" : "string", analyzer: "my_analyzer"}
                          filter_value: {"type" : "string" , analyzer: "my_analyzer"}
  </code></pre>
  
  <p>Each document has a lot of filters and it looks like:</p>
  
  <pre><code>"products_filter": [
  {
  "filter_name": "Rahmengröße",
  "filter_value": "33,5 cm"
  }
  ,
  {
  "filter_name": "color",
  "filter_value": "gelb"
  }
  ,
  {
  "filter_name": "Rahmengröße",
  "filter_value": "39,5 cm"
  }
  ,
  {
  "filter_name": "Rahmengröße",
  "filter_value": "45,5 cm"
  }]
  </code></pre>
  
  <p>I trying to get a list of unique filter names and list of unique filter values for each filter.</p>
  
  <p>I mean, I want to get structure like:
  Rahmengröße:<br/>
    39,5 cm<br/>
    45,5 cm  <br/>
    33,5 cm<br/>
  Color:<br/>
    gelb<br/></p>
  
  <p>To get it I tried few variants of aggregation, for example:</p>
  
  <pre><code>{
    "aggs": {
      "bla": {
        "terms": {
          "field": "products_filter.filter_name"
        },
        "aggs": {
          "bla2": {
            "terms": {
              "field": "products_filter.filter_value"
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>And this request is wrong. </p>
  
  <p>It will return me list of unique filter names, and each will contain list of ALL filter_values.</p>
  
  <pre><code>"bla": {
  "doc_count_error_upper_bound": 0,
  "sum_other_doc_count": 103,
  "buckets": [
  {
  "key": "color",
  "doc_count": 9,
  "bla2": {
  "doc_count_error_upper_bound": 4,
  "sum_other_doc_count": 366,
  "buckets": [
  {
  "key": "100",
  "doc_count": 5
  }
  ,
  {
  "key": "cm",
  "doc_count": 5
  }
  ,
  {
  "key": "unisex",
  "doc_count": 5
  }
  ,
  {
  "key": "11",
  "doc_count": 4
  }
  ,
  {
  "key": "160",
  "doc_count": 4
  }
  ,
  {
  "key": "22",
  "doc_count": 4
  }
  ,
  {
  "key": "a",
  "doc_count": 4
  }
  ,
  {
  "key": "alu",
  "doc_count": 4
  }
  ,
  {
  "key": "aluminium",
  "doc_count": 4
  }
  ,
  {
  "key": "aus",
  "doc_count": 4
  }
  ]
  }
  }
  ,
  </code></pre>
  
  <p>Additionally I tried to use Reverse nested aggregation, but it doesnt help me.</p>
  
  <p>So I think there some logical fault in my attempts?</p>