# How to aggregate on the same field:value which are specified in query in elasticsearch

**URL:** <https://discuss.elastic.co/t/how-to-aggregate-on-the-same-field-value-which-are-specified-in-query-in-elasticsearch/117007>\
**Category:** Elasticsearch\
**Created:** [January 25, 2018, 9:01am UTC](https://discuss.elastic.co/t/how-to-aggregate-on-the-same-field-value-which-are-specified-in-query-in-elasticsearch/117007 "2018-01-25T09:01:35Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![glady](https://avatars.discourse-cdn.com/v4/letter/g/48db29/32.png) [@glady](https://discuss.elastic.co/u/glady)\
**Post date:** [January 25, 2018, 9:01am UTC](https://discuss.elastic.co/t/how-to-aggregate-on-the-same-field-value-which-are-specified-in-query-in-elasticsearch/117007/1 "2018-01-25T09:01:36Z")

</div>

So my data in elasticsearch looks like this one whole dict with one person id is equal to one doc and it contains list of objects like {"dummy\_name": "abc","dummy\_id": "44850642"}which is shown below ,the thing is I am querying on the field dummy\_id and I am getting result as some no. of matching query results, and I want to aggregate the on dummy\_id field so I'll get no of docs for a specific dummy\_name, but what happening is I am also getting the buckets of dummy\_id which are not mentioned in the query its self as person contains list of objects in which dummy\_id is present. {  
"person\_id": 1234,  
"Properties": {  
"Property1": [  
{  
"dummy\_name": "abc",  
"dummy\_id": "44850642"  
},  
{},  
{}  
]  
}  
},  
{"person\_id": 1235,  
...  
...  
...  
}

Query I am using: {  
"query": {  
"bool": {  
"must": [  
{  
"match": {  
"Properties.Property1.concept\_id": "453041 23234324 124324 "  
}  
}  
]  
}  
},  
"aggregations": {  
"group\_by\_concept": {  
"terms": {  
"field": "Properties.Property1.concept\_id",  
"order": {  
"\_count": "desc"  
},  
"size": 10  
}  
}  
}  
}

---

<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:** [February 22, 2018, 9:01am UTC](https://discuss.elastic.co/t/how-to-aggregate-on-the-same-field-value-which-are-specified-in-query-in-elasticsearch/117007/2 "2018-02-22T09:01:37Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
