# How to aggregate term field only with query

**URL:** <https://discuss.elastic.co/t/how-to-aggregate-term-field-only-with-query/41706>\
**Category:** Elasticsearch\
**Created:** [February 14, 2016, 4:03am UTC](https://discuss.elastic.co/t/how-to-aggregate-term-field-only-with-query/41706 "2016-02-14T04:03:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fan158](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/fan158/32/7776_2.png) [@fan158](https://discuss.elastic.co/u/fan158)\
**Post date:** [February 14, 2016, 4:03am UTC](https://discuss.elastic.co/t/how-to-aggregate-term-field-only-with-query/41706/1 "2016-02-14T04:03:19Z")

</div>

eg:  
the values of "p6" only contains d the query clause, not filter by filter clause  
how to do ?? thanks !

"query": {  
"filtered": {  
"query": {  
"multi\_match": {  
"query": "testing",  
"fields": [ "field1"  
]  
}  
},  
"filter": {  
"bool": {  
"must": [{"term":{"field2":1}}]  
}  
}  
}  
},  
"aggregations": {  
"p6": {  
"terms": {  
"field": "p6"  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:16pm UTC](https://discuss.elastic.co/t/how-to-aggregate-term-field-only-with-query/41706/2 "2017-07-05T23:16:33Z")

</div>


