title: Elasticsearch 5 | filter nested object and nested aggregation count
body: <p>elasticsearch 5.2</p>
  
  <p>I want to filter my items by the nested object state.id = 101 and an aggregation count for all the items by state.id. There are items with the state ids 101, 102 and 103.</p>
  
  <p>The aggregation count is now limited to state.id 101. I want the only get the items with state.id = 101 and the aggregation count for all state ids.</p>
  
  <p>How can i do this?</p>
  
  <pre><code>GET index/items/_search
  {
    "query": {
          "nested" : {
              "path" : "state",
              "query": {
                "bool": {
                  "filter": {
                    "term": { "state.id": 101 }
                  }
                }
              }
          }
    },
       "aggs" : {
          "state" : {
              "nested" : {
                  "path" : "state"
              },
              "aggs" : {
                  "count" : { "terms" : { "field" : "state.id" } }
              }
          }
      }
  }
  </code></pre>