# Facets on Child Document

**URL:** <https://discuss.elastic.co/t/facets-on-child-document/14786>\
**Category:** Elasticsearch\
**Created:** [December 10, 2013, 3:29am UTC](https://discuss.elastic.co/t/facets-on-child-document/14786 "2013-12-10T03:29:31Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guozhu\_Wei](https://avatars.discourse-cdn.com/v4/letter/g/cc9497/32.png) [@Guozhu\_Wei](https://discuss.elastic.co/u/Guozhu_Wei)\
**Post date:** [December 10, 2013, 3:29am UTC](https://discuss.elastic.co/t/facets-on-child-document/14786/1 "2013-12-10T03:29:31Z")

</div>

ES Version: 0.90.7

I want to search on parent type and facets on child type, there is an  
example use case from  
[http://elasticsearch-users.115913.n3.nabble.com/Facets-on-child-documents-td](http://elasticsearch-users.115913.n3.nabble.com/Facets-on-child-documents-td)  
4037793.html

I followed the example:

* * *

* * *

* * *

Parent Docs  
curl -XPUT '[http://esvm1:9200/pc/respondent/1](http://esvm1:9200/pc/respondent/1)' -d '{"rid": 1, "date":  
"2011-11-18"}'  
curl -XPUT '[http://esvm1:9200/pc/respondent/2](http://esvm1:9200/pc/respondent/2)' -d '{"rid": 2, "date":  
"2011-11-19"}'  
curl -XPUT '[http://esvm1:9200/pc/respondent/3](http://esvm1:9200/pc/respondent/3)' -d '{"rid": 3, "date":  
"2011-11-17"}'  
curl -XPUT '[http://esvm1:9200/pc/respondent/4](http://esvm1:9200/pc/respondent/4)' -d '{"rid": 4, "date":  
"2011-11-18"}'  
curl -XPUT '[http://esvm1:9200/pc/respondent/5](http://esvm1:9200/pc/respondent/5)' -d '{"rid": 5, "date":  
"2011-11-18"}'  
curl -XPUT '[http://esvm1:9200/pc/respondent/6](http://esvm1:9200/pc/respondent/6)' -d '{"rid": 6, "date":  
"2011-11-19"}'

# Insert some maps (Child docs) that happened to those respondents:

# 

curl -XPOST '[http://esvm1:9200/pc/map/1\_100?parent=1](http://esvm1:9200/pc/map/1_100?parent=1)' -d '{"mapid": 100,  
"value": 1}'  
curl -XPOST '[http://esvm1:9200/pc/map/1\_102?parent=1](http://esvm1:9200/pc/map/1_102?parent=1)' -d '{"mapid": 102,  
"text": "hi"}'  
curl -XPOST '[http://esvm1:9200/pc/map/2\_100?parent=2](http://esvm1:9200/pc/map/2_100?parent=2)' -d '{"mapid": 100,  
"value": 2}'  
curl -XPOST '[http://esvm1:9200/pc/map/2\_101?parent=2](http://esvm1:9200/pc/map/2_101?parent=2)' -d '{"mapid": 101,  
"value": 1}'  
curl -XPOST '[http://esvm1:9200/pc/map/3\_101?parent=3](http://esvm1:9200/pc/map/3_101?parent=3)' -d '{"mapid": 101,  
"value": 1}'  
curl -XPOST '[http://esvm1:9200/pc/map/3\_102?parent=3](http://esvm1:9200/pc/map/3_102?parent=3)' -d '{"mapid": 102,  
"text": "hello"}'  
curl -XPOST '[http://esvm1:9200/pc/map/4\_100?parent=4](http://esvm1:9200/pc/map/4_100?parent=4)' -d '{"mapid": 100,  
"value": 1}'  
curl -XPOST '[http://esvm1:9200/pc/map/5\_100?parent=5](http://esvm1:9200/pc/map/5_100?parent=5)' -d '{"mapid": 100,  
"value": 2}'  
curl -XPOST '[http://esvm1:9200/pc/map/6\_100?parent=6](http://esvm1:9200/pc/map/6_100?parent=6)' -d '{"mapid": 100,  
"value": 1}'

POST [http://esvm1:9200/pc/respondent/\_search](http://esvm1:9200/pc/respondent/_search)  
{  
"query" : {  
"has\_child" : {  
"type" : "map",  
"query" : {  
"match" : {  
"mapid" : "101"  
}  
}  
}  
},  
"facets" : {  
"term1" : {  
"terms" : {  
"field" : "value"  
},  
"global" : true,  
"facet\_filter" : {  
"term" : {  
"mapid" : "100"  
}  
}  
}  
}  
}

* * *

* * *

* * *

In the post  
[http://elasticsearch-users.115913.n3.nabble.com/Facets-on-child-documents-td](http://elasticsearch-users.115913.n3.nabble.com/Facets-on-child-documents-td)  
4037793.html , it said that we can get response:

terms: [  
{ term: 1, count: 3},  
{ term: 2, count: 2}  
]

But in my experiment, no facets were returned,

"facets": {  
"term1": {  
"\_type": "terms",  
"missing": 0,  
"total": 0,  
"other": 0,  
"terms": []  
}  
}

I find the same use case related to this purpose:  
[https://github.com/elasticsearch/elasticsearch/issues/2606](https://github.com/elasticsearch/elasticsearch/issues/2606) , but it seems  
not work in 0.90.7 too.

Any idea? 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).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/006e01cef558%240c6584f0%2425308ed0%24%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/006e01cef558%240c6584f0%2425308ed0%24%40gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![mvg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mvg/32/98890_2.png) [@mvg](https://discuss.elastic.co/u/mvg)\
**Post date:** [December 12, 2013, 9:13pm UTC](https://discuss.elastic.co/t/facets-on-child-document/14786/2 "2013-12-12T21:13:03Z")

</div>

If you don't the respondent type in the path of the url, then the global.  
facet does return entries.  
The type in the url path is used as filter for the query and also the  
global facet.

On 10 December 2013 04:29, Guozhu Wei [weiguozhu@gmail.com](mailto:weiguozhu@gmail.com) wrote:

> ES Version: 0.90.7
> 
> I want to search on parent type and facets on child type, there is an  
> example use case from
> 
> [http://elasticsearch-users.115913.n3.nabble.com/Facets-on-child-documents-td](http://elasticsearch-users.115913.n3.nabble.com/Facets-on-child-documents-td)  
> 4037793.html
> 
> I followed the example:
> 
> * * *
> 
> * * *
> 
> * * *
> 
> Parent Docs  
> curl -XPUT '[http://esvm1:9200/pc/respondent/1](http://esvm1:9200/pc/respondent/1)' -d '{"rid": 1, "date":  
> "2011-11-18"}'  
> curl -XPUT '[http://esvm1:9200/pc/respondent/2](http://esvm1:9200/pc/respondent/2)' -d '{"rid": 2, "date":  
> "2011-11-19"}'  
> curl -XPUT '[http://esvm1:9200/pc/respondent/3](http://esvm1:9200/pc/respondent/3)' -d '{"rid": 3, "date":  
> "2011-11-17"}'  
> curl -XPUT '[http://esvm1:9200/pc/respondent/4](http://esvm1:9200/pc/respondent/4)' -d '{"rid": 4, "date":  
> "2011-11-18"}'  
> curl -XPUT '[http://esvm1:9200/pc/respondent/5](http://esvm1:9200/pc/respondent/5)' -d '{"rid": 5, "date":  
> "2011-11-18"}'  
> curl -XPUT '[http://esvm1:9200/pc/respondent/6](http://esvm1:9200/pc/respondent/6)' -d '{"rid": 6, "date":  
> "2011-11-19"}'
> 
> # Insert some maps (Child docs) that happened to those respondents:
> 
> # 
> 
> curl -XPOST '[http://esvm1:9200/pc/map/1\_100?parent=1](http://esvm1:9200/pc/map/1_100?parent=1)' -d '{"mapid": 100,  
> "value": 1}'  
> curl -XPOST '[http://esvm1:9200/pc/map/1\_102?parent=1](http://esvm1:9200/pc/map/1_102?parent=1)' -d '{"mapid": 102,  
> "text": "hi"}'  
> curl -XPOST '[http://esvm1:9200/pc/map/2\_100?parent=2](http://esvm1:9200/pc/map/2_100?parent=2)' -d '{"mapid": 100,  
> "value": 2}'  
> curl -XPOST '[http://esvm1:9200/pc/map/2\_101?parent=2](http://esvm1:9200/pc/map/2_101?parent=2)' -d '{"mapid": 101,  
> "value": 1}'  
> curl -XPOST '[http://esvm1:9200/pc/map/3\_101?parent=3](http://esvm1:9200/pc/map/3_101?parent=3)' -d '{"mapid": 101,  
> "value": 1}'  
> curl -XPOST '[http://esvm1:9200/pc/map/3\_102?parent=3](http://esvm1:9200/pc/map/3_102?parent=3)' -d '{"mapid": 102,  
> "text": "hello"}'  
> curl -XPOST '[http://esvm1:9200/pc/map/4\_100?parent=4](http://esvm1:9200/pc/map/4_100?parent=4)' -d '{"mapid": 100,  
> "value": 1}'  
> curl -XPOST '[http://esvm1:9200/pc/map/5\_100?parent=5](http://esvm1:9200/pc/map/5_100?parent=5)' -d '{"mapid": 100,  
> "value": 2}'  
> curl -XPOST '[http://esvm1:9200/pc/map/6\_100?parent=6](http://esvm1:9200/pc/map/6_100?parent=6)' -d '{"mapid": 100,  
> "value": 1}'
> 
> POST [http://esvm1:9200/pc/respondent/\_search](http://esvm1:9200/pc/respondent/_search)  
> {  
> "query" : {  
> "has\_child" : {  
> "type" : "map",  
> "query" : {  
> "match" : {  
> "mapid" : "101"  
> }  
> }  
> }  
> },  
> "facets" : {  
> "term1" : {  
> "terms" : {  
> "field" : "value"  
> },  
> "global" : true,  
> "facet\_filter" : {  
> "term" : {  
> "mapid" : "100"  
> }  
> }  
> }  
> }  
> }
> 
> * * *
> 
> * * *
> 
> * * *
> 
> In the post
> 
> [http://elasticsearch-users.115913.n3.nabble.com/Facets-on-child-documents-td](http://elasticsearch-users.115913.n3.nabble.com/Facets-on-child-documents-td)  
> 4037793.html , it said that we can get response:
> 
> terms: [  
> { term: 1, count: 3},  
> { term: 2, count: 2}  
> ]
> 
> But in my experiment, no facets were returned,
> 
> "facets": {  
> "term1": {  
> "\_type": "terms",  
> "missing": 0,  
> "total": 0,  
> "other": 0,  
> "terms":   
> }  
> }
> 
> I find the same use case related to this purpose:  
> [Remove scope support in query and facet dsl. · Issue #2606 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2606) , but it seems  
> not work in 0.90.7 too.
> 
> Any idea? 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).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/006e01cef558%240c6584f0%2425308ed0%24%40gmail.com](https://groups.google.com/d/msgid/elasticsearch/006e01cef558%240c6584f0%2425308ed0%24%40gmail.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
Met vriendelijke groet,

Martijn van Groningen

--  
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/CA%2BA76TxUj0ZHLXNnSBpGoPvPbvZsh7UL3LGYepckAwWNdASZmQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CA%2BA76TxUj0ZHLXNnSBpGoPvPbvZsh7UL3LGYepckAwWNdASZmQ%40mail.gmail.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:01am UTC](https://discuss.elastic.co/t/facets-on-child-document/14786/3 "2017-07-06T02:01:36Z")

</div>


