# Aggregations on Named Filters

**URL:** <https://discuss.elastic.co/t/aggregations-on-named-filters/20699>\
**Category:** Elasticsearch\
**Created:** [November 11, 2014, 10:07pm UTC](https://discuss.elastic.co/t/aggregations-on-named-filters/20699 "2014-11-11T22:07:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kenneth\_Yeatman](https://avatars.discourse-cdn.com/v4/letter/k/5f8ce5/32.png) [@Kenneth\_Yeatman](https://discuss.elastic.co/u/Kenneth_Yeatman)\
**Post date:** [November 11, 2014, 10:07pm UTC](https://discuss.elastic.co/t/aggregations-on-named-filters/20699/1 "2014-11-11T22:07:42Z")

</div>

I have just a general question for the group. Is it possible to perform an  
aggregation on the matched\_queries field array from a named filter? I  
have the the query at the bottom that I would like to perform (I simplified  
it here). I can have potentially a number of user defined queries that I  
would like to aggregate on geohashes AND return the number of distinct  
queries matched in each hash. For this example, the query would be for the  
count of McDonalds and Starbucks but also if they both occur in the same  
geohash. Right now, I'm doing it in two queries and performing the joins  
in other code but I was looking for an ES only solution.

Thanks,  
Ken

Query:  
{  
"aggs": {  
"geohash": {  
"geohash\_grid": {  
"field": "coordinates",  
"precision": 3  
},  
"aggregations": {  
"subcount": {  
"": {  
"field": "matched\_queries"  
}  
}  
}  
}  
},  
"query": {  
"filtered": {  
"filter": {  
"or": [  
{  
"fquery": {  
"query": {  
"query\_string": {  
"query": "McDonalds"  
}  
},  
"\_name": "McDonalds"  
}  
},  
{  
"fquery": {  
"query": {  
"query\_string": {  
"query": "Starbucks"  
}  
},  
"\_name": "Starbucks"  
}  
}  
]  
},  
"query": {  
"match\_all": {}  
}  
}  
},  
"size": 100  
}

Mock Response:  
"geohash": {

- "buckets": [
  - {
    - "key": "abc",
    - "doc\_count": 2328,
    - "subcount": {
      - "buckets": [2]  
}  
},

  - {
    - "key": "abd",
    - "doc\_count": 13,
    - "subcount": {
      - "buckets": [1]  
}  
}

  - ...

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/570fd717-ddea-43c7-8078-5e0bc4f922a3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/570fd717-ddea-43c7-8078-5e0bc4f922a3%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:50am UTC](https://discuss.elastic.co/t/aggregations-on-named-filters/20699/2 "2017-07-06T00:50:41Z")

</div>


