# Aggregations with object type properties

**URL:** <https://discuss.elastic.co/t/aggregations-with-object-type-properties/18700>\
**Category:** Elasticsearch\
**Created:** [July 16, 2014, 1:50pm UTC](https://discuss.elastic.co/t/aggregations-with-object-type-properties/18700 "2014-07-16T13:50:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amine\_Benhalloum](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amine_benhalloum/32/1394_2.png) [@Amine\_Benhalloum](https://discuss.elastic.co/u/Amine_Benhalloum)\
**Post date:** [July 16, 2014, 1:50pm UTC](https://discuss.elastic.co/t/aggregations-with-object-type-properties/18700/1 "2014-07-16T13:50:54Z")

</div>

Hi everyone,

I am trying to figure something out :

Here's an example of a document that contains object properties, and then  
trying to do simple terms aggregations.

> <https://gist.github.com/BAmine/80e1be219d2ac272561a>

The response I get :  
{  
"took": 2,  
"timed\_out": false,  
"\_shards": {  
"total": 5,  
"successful": 5,  
"failed": 0  
},  
"hits": {  
"total": 1,  
"max\_score": 0,  
"hits": []  
},  
"aggregations": {  
"test": {  
"buckets": [  
{  
"key": "canine",  
"doc\_count": 1,  
"test2": {  
"buckets": [  
{  
"key": "cat",  
"doc\_count": 1  
},  
{  
"key": "dog",  
"doc\_count": 1  
},  
{  
"key": "tiger",  
"doc\_count": 1  
},  
{  
"key": "wolf",  
"doc\_count": 1  
}  
]  
}  
},  
{  
"key": "feline",  
"doc\_count": 1,  
"test2": {  
"buckets": [  
{  
"key": "cat",  
"doc\_count": 1  
},  
{  
"key": "dog",  
"doc\_count": 1  
},  
{  
"key": "tiger",  
"doc\_count": 1  
},  
{  
"key": "wolf",  
"doc\_count": 1  
}  
]  
}  
}  
]  
}  
}  
}

The question is : How can I avoid getting, in my sub-aggregations, buckets  
whose keys do not belong to the parent aggregation's keys ( example : cat  
and tiger are not in the property whose label is feline ) ?  
Is there a way to do this without using nested properties ?

Thank you !

--  
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/2fb7d54b-9a52-4583-ae62-f95cbf1c5e35%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/2fb7d54b-9a52-4583-ae62-f95cbf1c5e35%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Michael\_Sander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_sander/32/838_2.png) [@Michael\_Sander](https://discuss.elastic.co/u/Michael_Sander)\
**Post date:** [July 16, 2014, 2:00pm UTC](https://discuss.elastic.co/t/aggregations-with-object-type-properties/18700/2 "2014-07-16T14:00:37Z")

</div>

There are several ways of ding this. Probably the easiest is to add nested  
objects to your mapping. Read more here:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

On Wednesday, July 16, 2014 9:50:54 AM UTC-4, Amine Benhalloum wrote:

> Hi everyone,
> 
> I am trying to figure something out :
> 
> Here's an example of a document that contains object properties, and then  
> trying to do simple terms aggregations.  
> [Aggregation example · GitHub](https://gist.github.com/BAmine/80e1be219d2ac272561a)
> 
> The response I get :  
> {  
> "took": 2,  
> "timed\_out": false,  
> "\_shards": {  
> "total": 5,  
> "successful": 5,  
> "failed": 0  
> },  
> "hits": {  
> "total": 1,  
> "max\_score": 0,  
> "hits":   
> },  
> "aggregations": {  
> "test": {  
> "buckets": [  
> {  
> "key": "canine",  
> "doc\_count": 1,  
> "test2": {  
> "buckets": [  
> {  
> "key": "cat",  
> "doc\_count": 1  
> },  
> {  
> "key": "dog",  
> "doc\_count": 1  
> },  
> {  
> "key": "tiger",  
> "doc\_count": 1  
> },  
> {  
> "key": "wolf",  
> "doc\_count": 1  
> }  
> ]  
> }  
> },  
> {  
> "key": "feline",  
> "doc\_count": 1,  
> "test2": {  
> "buckets": [  
> {  
> "key": "cat",  
> "doc\_count": 1  
> },  
> {  
> "key": "dog",  
> "doc\_count": 1  
> },  
> {  
> "key": "tiger",  
> "doc\_count": 1  
> },  
> {  
> "key": "wolf",  
> "doc\_count": 1  
> }  
> ]  
> }  
> }  
> ]  
> }  
> }  
> }
> 
> The question is : How can I avoid getting, in my sub-aggregations, buckets  
> whose keys do not belong to the parent aggregation's keys ( example : cat  
> and tiger are not in the property whose label is feline ) ?  
> Is there a way to do this without using nested properties ?
> 
> Thank you !

--  
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/f0529c6e-81cf-4a96-a95b-8b7274ea1f06%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/f0529c6e-81cf-4a96-a95b-8b7274ea1f06%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Amine\_Benhalloum](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/amine_benhalloum/32/1394_2.png) [@Amine\_Benhalloum](https://discuss.elastic.co/u/Amine_Benhalloum)\
**Post date:** [July 16, 2014, 2:14pm UTC](https://discuss.elastic.co/t/aggregations-with-object-type-properties/18700/3 "2014-07-16T14:14:05Z")

</div>

Hi Michael, and thank you for your answer.

I would rather not use nested objects because it will hurt the performance  
of my application.  
Do you know of any another way ?

--  
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/3860607a-69fb-4eee-b673-7bfb1712dbd3%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/3860607a-69fb-4eee-b673-7bfb1712dbd3%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, 1:15am UTC](https://discuss.elastic.co/t/aggregations-with-object-type-properties/18700/4 "2017-07-06T01:15:28Z")

</div>


