# Facets on children

**URL:** <https://discuss.elastic.co/t/facets-on-children/11356>\
**Category:** Elasticsearch\
**Created:** [March 28, 2013, 2:06pm UTC](https://discuss.elastic.co/t/facets-on-children/11356 "2013-03-28T14:06:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Udi\_Ben\_Amitai](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/udi_ben_amitai/32/805_2.png) [@Udi\_Ben\_Amitai](https://discuss.elastic.co/u/Udi_Ben_Amitai)\
**Post date:** [March 28, 2013, 2:06pm UTC](https://discuss.elastic.co/t/facets-on-children/11356/1 "2013-03-28T14:06:34Z")

</div>

Hello,  
Is there a way to create a facet on children when querying on parent? Is it  
even makes sence?  
I have this mapping:  
{  
"mappings" : {  
"parentType" : {  
"properties" : {  
"id" : { "type" : "long"},  
"price": { "type" : "double" }  
}  
},  
"childType": {  
"\_parent": {"type": "parentType"},  
"properties": {  
"id": {"type": "long"},  
"count": {"type":"long"}  
}  
}  
}

}

I want to create a query like facet on nested element:  
{  
"query": {  
"match\_all":{}  
},  
"facets":{  
"count\_facet":{  
"terms": {  
"field": "count"  
},  
"nested": "childType"  
}  
}  
}

Is there a way of achiving facets on the children?

Thanks

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mattweber](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mattweber/32/44940_2.png) [@mattweber](https://discuss.elastic.co/u/mattweber)\
**Post date:** [April 3, 2013, 12:28am UTC](https://discuss.elastic.co/t/facets-on-children/11356/2 "2013-04-03T00:28:59Z")

</div>

I think something like this will work.....

{  
"facets": {  
"count\_facet": {  
"terms": {  
"field": "count"  
},  
"global": true,  
"facet\_filter": {  
"has\_parent": {  
"query": {  
"match\_all": {}  
},  
"parent\_type": "parentType"  
}  
}  
}  
},  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"type": {  
"value": "parentType"  
}  
}  
}  
}  
}

On Thu, Mar 28, 2013 at 7:06 AM, Udi Ben Amitai [sabaudi@gmail.com](mailto:sabaudi@gmail.com) wrote:

> Hello,  
> Is there a way to create a facet on children when querying on parent? Is  
> it even makes sence?  
> I have this mapping:  
> {  
> "mappings" : {  
> "parentType" : {  
> "properties" : {  
> "id" : { "type" : "long"},  
> "price": { "type" : "double" }  
> }  
> },  
> "childType": {  
> "\_parent": {"type": "parentType"},  
> "properties": {  
> "id": {"type": "long"},  
> "count": {"type":"long"}  
> }  
> }  
> }
> 
> }
> 
> I want to create a query like facet on nested element:  
> {  
> "query": {  
> "match\_all":{}  
> },  
> "facets":{  
> "count\_facet":{  
> "terms": {  
> "field": "count"  
> },  
> "nested": "childType"  
> }  
> }  
> }
> 
> Is there a way of achiving facets on the children?
> 
> Thanks
> 
> --  
> 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).  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 2:43am UTC](https://discuss.elastic.co/t/facets-on-children/11356/3 "2017-07-06T02:43:09Z")

</div>


