title: Nested filter in Elasticsearch aggregation query
body: <p>I am running following aggregation query with nested filter </p>
  
  <pre><code>GET &lt;indexname&gt;/_search
  {
    "aggs": {
      "NAME": {
        "nested": {
          "path": "crm.LeadStatusHistory"
        },
        "aggs": {
          "agg_filter": {
            "filter": {
              "bool": {
                "must": [
                  {
                    "nested": {
                      "path": "crm",
                      "query": {
                        "terms": {
                          "crm.City.keyword": [
                            "Rewa"
                          ]
                        }
                      }
                    }
                  },
                  {
                    "nested": {
                      "path": "crm",
                      "query": {
                        "terms": {
                          "crm.LeadID": [
                            27961
                          ]
                        }
                      }
                    }
                  }
                ]
              }
            },
            "aggs": {
              "agg_terms":{
                "terms": {
                  "field": "crm.LeadStatusHistory.StatusID",
                  "size": 1000
                }
              }
            }
          }
        }
      }
    }
  }
  </code></pre>
  
  <p>-----> i have following document </p>
  
  <pre><code>{
          "_index" : "crm",
          "_type" : "_doc",
          "_id" : "4478",
          "_score" : 1.0,
          "_source" : {
            "crm" : [
              {
                "LeadStatusHistory" : [
                  {
                    "StatusID" : 3
                  },
                  {
                    "StatusID" : 2
                  },
                  {
                    "StatusID" : 1
                  }
                ],
                "LeadID" : 27961,
                "City" : "Rewa"
              },
              {
                "LeadStatusHistory" : [
                  {
                    "StatusID" : 1
                  },
                  {
                    "StatusID" : 3
                  },
                  {
                    "StatusID" : 2
                  }
                ],
                "LeadID" : 27959,
                "City" : "Rewa"
              }
            ]
          }
        }]
  </code></pre>
  
  <p>However in response i am getting following result</p>
  
  <pre><code>"aggregations" : {
      "NAME" : {
        "doc_count" : 4332,
        "agg_filter" : {
          "doc_count" : 1,
          "agg_terms" : {
            "doc_count_error_upper_bound" : 0,
            "sum_other_doc_count" : 0,
            "buckets" : [
              {
                "key" : 1,
                "doc_count" : 1
              }
            ]
          }
        }
      }
    }
  </code></pre>
  
  <p>Query===> As per source document, i have 3 nested 'crm.LeadStatusHistory' documents for crm.LeadID = 27961. However, results shows for agg_filter equals to 1 instead of 3. Can you please let me know the reason for this case.</p>