# Has\_child in facet?

**URL:** https://discuss.elastic.co/t/has-child-in-facet/3977
**Category:** Elasticsearch
**Created:** [February 25, 2011, 2:35am UTC](https://discuss.elastic.co/t/has-child-in-facet/3977 "2011-02-25T02:35:56Z")
**Posts on this page:** 14
**Page:** 1

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [February 25, 2011, 2:35am UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/1 "2011-02-25T02:35:56Z")

</div>

Hi,

Very new to elasticsearch, but also very impressed (coming from using  
FAST ESP). One question that I've come up to, is that I'm trying to  
determine if it's possible to use a has\_child (either filter or query)  
in a facet?

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [February 25, 2011, 2:40am UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/2 "2011-02-25T02:40:21Z")

</div>

It should be possible, never tested it though (use has\_child filter as a facet filter). Note that has\_child filter can be expensive, so it might make more sense to redesign the doc structure.  
On Friday, February 25, 2011 at 4:35 AM, Matt Paul wrote:

> Hi,
> 
> Very new to elasticsearch, but also very impressed (coming from using  
> FAST ESP). One question that I've come up to, is that I'm trying to  
> determine if it's possible to use a has\_child (either filter or query)  
> in a facet?

---

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [February 25, 2011, 2:50am UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/3 "2011-02-25T02:50:37Z")

</div>

Thanks for the quick reply! The child structure contains often updated  
fields (and the parent can potentially have large text blocks,  
sometimes multi-meg), so I figured that putting the those fields that  
change in a child document would keep the majority of the data from  
having to be reindexed on updates (like I said, I'm new, but I thought  
that was the basic intent of parent/child?). Anyway, here's what I'm  
trying to do, and the error I'm getting (matchall on the query part  
only for the example):

curl -XPOST "[http://localhost:9200/1861\_active/\_search?pretty=true](http://localhost:9200/1861_active/_search?pretty=true)" -  
d  
'{"query" : {  
"matchAll" : {}},  
"facets" : {  
"results" : {  
"filter" : {  
"has\_child" : {  
"type" : "results",  
"query" : {  
"term" : {"rsvb" : "1"}  
}  
}  
}  
}  
}  
}'

here's the error:

{  
"error" : "SearchPhaseExecutionException[Failed to execute phase  
[query], total failure; shardFailures {[a0-heKheQqytwK2yhJD3tQ]  
[1861\_30c77ae1ebe541dbbab4740121d1c76a][0]:  
QueryPhaseExecutionException[[1861\_30c77ae1ebe541dbbab4740121d1c76a]  
[0]: query[ConstantScore(_:_)],from[0],size[10]: Query Failed [Failed  
to execute main query]]; nested: }{[a0-heKheQqytwK2yhJD3tQ]  
[1861\_30c77ae1ebe541dbbab4740121d1c76a][1]:  
QueryPhaseExecutionException[[1861\_30c77ae1ebe541dbbab4740121d1c76a]  
[1]: query[ConstantScore(_:_)],from[0],size[10]: Query Failed [Failed  
to execute main query]]; nested: }{[a0-heKheQqytwK2yhJD3tQ]  
[1861\_30c77ae1ebe541dbbab4740121d1c76a][2]:  
QueryPhaseExecutionException[[1861\_30c77ae1ebe541dbbab4740121d1c76a]  
[2]: query[ConstantScore(_:_)],from[0],size[10]: Query Failed [Failed  
to execute main query]]; nested: }{[a0-heKheQqytwK2yhJD3tQ]  
[1861\_30c77ae1ebe541dbbab4740121d1c76a][3]:  
QueryPhaseExecutionException[[1861\_30c77ae1ebe541dbbab4740121d1c76a]  
[3]: query[ConstantScore(_:_)],from[0],size[10]: Query Failed [Failed  
to execute main query]]; nested: }{[a0-heKheQqytwK2yhJD3tQ]  
[1861\_30c77ae1ebe541dbbab4740121d1c76a][4]:  
QueryPhaseExecutionException[[1861\_30c77ae1ebe541dbbab4740121d1c76a]  
[4]: query[ConstantScore(_:_)],from[0],size[10]: Query Failed [Failed  
to execute main query]]; nested: }]",  
"status" : 500

and here's what's in the child (results):

curl -XPOST "[http://localhost:9200/1861\_active/results/\_search](http://localhost:9200/1861_active/results/_search)?  
pretty=true" -d '{"query" : { "matchAll" : {}}}'  
{  
"took" : 3,  
"timed\_out" : false,  
"\_shards" : {  
"total" : 5,  
"successful" : 5,  
"failed" : 0  
},  
"hits" : {  
"total" : 2,  
"max\_score" : 1.0,  
"hits" : [ {  
"\_index" : "1861\_30c77ae1ebe541dbbab4740121d1c76a",  
"\_type" : "results",  
"\_id" : "8231e9f27b0c46bcb3a51144a260dd80:81",  
"\_score" : 1.0, "\_source" : { "rsvb" : 81, "rsvt" :  
1298513264000, "\_id" : "8231e9f27b0c46bcb3a51144a260dd80:81",  
"\_parent" : "8231e9f27b0c46bcb3a51144a260dd80:81" }  
}, {  
"\_index" : "1861\_30c77ae1ebe541dbbab4740121d1c76a",  
"\_type" : "results",  
"\_id" : "638004ea46d6454b947bff9d6878c342:81",  
"\_score" : 1.0, "\_source" : { "rsvb" : 81, "rsvt" :  
1298573507000, "\_id" : "638004ea46d6454b947bff9d6878c342:81",  
"\_parent" : "638004ea46d6454b947bff9d6878c342:81" }  
} ]  
}

Not quite sure what I'm doing wrong?

---

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [February 25, 2011, 2:55am UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/4 "2011-02-25T02:55:19Z")

</div>

Probably should also include, here's what an insert on the child table  
looks like (using bulk inserts):

{ "index" : { "\_index" : "1861\_active", "\_type" : "results", "\_id" :  
"8a08dfb3af854f07b72b04b977f27f2a:81", "\_parent" :  
"8a08dfb3af854f07b72b04b977f27f2a:81" } }  
{ "rsvb" : 81, "rsvt" : 1298602356000, "\_id" :  
"8a08dfb3af854f07b72b04b977f27f2a:81", "\_parent" :  
"8a08dfb3af854f07b72b04b977f27f2a:81" }

---

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [February 25, 2011, 2:56am UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/5 "2011-02-25T02:56:42Z")

</div>

Additionally, here's the insert on the child (bulk insert):  
{ "index" : { "\_index" : "1861\_active", "\_type" : "results", "\_id" :  
"8a08dfb3af854f07b72b04b977f27f2a:81", "\_parent" :  
"8a08dfb3af854f07b72b04b977f27f2a:81" } }  
{ "rsvb" : 81, "rsvt" : 1298602356000, "\_id" :  
"8a08dfb3af854f07b72b04b977f27f2a:81", "\_parent" :  
"8a08dfb3af854f07b72b04b977f27f2a:81" }

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [February 25, 2011, 7:54pm UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/6 "2011-02-25T19:54:50Z")

</div>

Can you create a recreation based on [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://elasticsearch.org/help)?  
On Friday, February 25, 2011 at 4:56 AM, Matt Paul wrote:

> Additionally, here's the insert on the child (bulk insert):  
> { "index" : { "\_index" : "1861\_active", "\_type" : "results", "\_id" :  
> "8a08dfb3af854f07b72b04b977f27f2a:81", "\_parent" :  
> "8a08dfb3af854f07b72b04b977f27f2a:81" } }  
> { "rsvb" : 81, "rsvt" : 1298602356000, "\_id" :  
> "8a08dfb3af854f07b72b04b977f27f2a:81", "\_parent" :  
> "8a08dfb3af854f07b72b04b977f27f2a:81" }

---

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [February 25, 2011, 9:56pm UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/7 "2011-02-25T21:56:13Z")

</div>

Shay,

Here you go. While creating this example, I think I found that the culprit  
has something to do with the alias I'm creating for the index (it doesn't  
error out if I don't use aliasing at all):

curl -XPUT "[http://localhost:9200/err\_test\_real](http://localhost:9200/err_test_real)" -d '{ "mappings" :  
{ "results" : { "\_parent" : { "type" : "doc" }}}}'  
curl  
-XPUT "[http://localhost:9200/err\_test\_real/doc/8a08dfb3af854f07b72b04b977f27f2a:81](http://localhost:9200/err_test_real/doc/8a08dfb3af854f07b72b04b977f27f2a:81)"  
-d '{ "col" : "some\_data", "\_id" : "8a08dfb3af854f07b72b04b977f27f2a:81" }'  
curl -XPOST "[http://localhost:9200/\_aliases](http://localhost:9200/_aliases)" -d '{"add" :  
{"index" : "err\_test\_real", "alias" : "err\_test"}}'  
curl  
-XPUT "[http://localhost:9200/err\_test/results/8a08dfb3af854f07b72b04b977f27f2a:81?parent=8a08dfb3af854f07b72b04b977f27f2a:81](http://localhost:9200/err_test/results/8a08dfb3af854f07b72b04b977f27f2a:81?parent=8a08dfb3af854f07b72b04b977f27f2a:81)"  
-d'{ "child\_column" :  
42, "\_id" : "8a08dfb3af854f07b72b04b977f27f2a:81", "\_parent" : "8a08dfb3af854f07b72b04b977f27f2a:81"  
}'  
curl -XPOST "[http://localhost:9200/err\_test/\_refresh](http://localhost:9200/err_test/_refresh)"  
curl -XPOST "[http://localhost:9200/err\_test/doc/\_search?pretty=true](http://localhost:9200/err_test/doc/_search?pretty=true)"  
-d '{"query" : { "matchAll" : {}}},  
"facets" : {  
"results" : {  
"filter" : {  
"has\_child" : {  
"type" : "results",  
"query" : {  
"term" : {"child\_column" : 42}  
}  
}  
}  
}  
}'

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [February 26, 2011, 10:27pm UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/8 "2011-02-26T22:27:05Z")

</div>

Please gist it.  
On Friday, February 25, 2011 at 11:56 PM, [purplegherkin@gmail.com](mailto:purplegherkin@gmail.com) wrote:

> Shay,
> 
> Here you go. While creating this example, I think I found that the culprit has something to do with the alias I'm creating for the index (it doesn't error out if I don't use aliasing at all):
> 
> curl -XPUT "[http://localhost:9200/err\_test\_real](http://localhost:9200/err_test_real)" -d '{ "mappings" : { "results" : { "\_parent" : { "type" : "doc" }}}}'  
> curl -XPUT "[http://localhost:9200/err\_test\_real/doc/8a08dfb3af854f07b72b04b977f27f2a:81](http://localhost:9200/err_test_real/doc/8a08dfb3af854f07b72b04b977f27f2a:81)" -d '{ "col" : "some\_data", "\_id" : "8a08dfb3af854f07b72b04b977f27f2a:81" }'  
> curl -XPOST "[http://localhost:9200/\_aliases](http://localhost:9200/_aliases)" -d '{"add" : {"index" : "err\_test\_real", "alias" : "err\_test"}}'  
> curl -XPUT "[http://localhost:9200/err\_test/results/8a08dfb3af854f07b72b04b977f27f2a:81?parent=8a08dfb3af854f07b72b04b977f27f2a:81](http://localhost:9200/err_test/results/8a08dfb3af854f07b72b04b977f27f2a:81?parent=8a08dfb3af854f07b72b04b977f27f2a:81)" -d'{ "child\_column" : 42, "\_id" : "8a08dfb3af854f07b72b04b977f27f2a:81", "\_parent" : "8a08dfb3af854f07b72b04b977f27f2a:81" }'  
> curl -XPOST "[http://localhost:9200/err\_test/\_refresh](http://localhost:9200/err_test/_refresh)"  
> curl -XPOST "[http://localhost:9200/err\_test/doc/\_search?pretty=true](http://localhost:9200/err_test/doc/_search?pretty=true)" -d '{"query" : { "matchAll" : {}}},  
> "facets" : {  
> "results" : {  
> "filter" : {  
> "has\_child" : {  
> "type" : "results",  
> "query" : {  
> "term" : {"child\_column" : 42}  
> }  
> }  
> }  
> }  
> }'

---

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [February 28, 2011, 5:23pm UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/9 "2011-02-28T17:23:22Z")

</div>

Shay,

Here ya go: git://gist.github.com/847657.git

thanks for taking a look!

Matt

---

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [February 28, 2011, 9:28pm UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/10 "2011-02-28T21:28:00Z")

</div>

Sorry, that should have read: [facet has\_child error example · GitHub](https://gist.github.com/847657)

On Feb 28, 2011 11:23am, [purplegherkin@gmail.com](mailto:purplegherkin@gmail.com) wrote:

> Shay,

> Here ya go: git://gist.github.com/847657.git

> thanks for taking a look!

> Matt

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [March 1, 2011, 2:49am UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/11 "2011-03-01T02:49:23Z")

</div>

Heya,

Several problems with the search request (the json is malformed). But, in any case, this did not work properly. Here is a gist of an example of how it should work: [gist:848506 · GitHub](https://gist.github.com/848506), and support for that has been pushed to master ([Search: Allow to use has\_child filter in facets · Issue #730 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/730)).

-shay.banon  
On Monday, February 28, 2011 at 11:28 PM, [purplegherkin@gmail.com](mailto:purplegherkin@gmail.com) wrote:

> Sorry, that should have read: [facet has\_child error example · GitHub](https://gist.github.com/847657)
> 
> On Feb 28, 2011 11:23am, [purplegherkin@gmail.com](mailto:purplegherkin@gmail.com) wrote:
> 
> > Shay,
> > 
> > Here ya go: git://gist.github.com/847657.git
> > 
> > thanks for taking a look!
> > 
> > Matt

---

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [March 1, 2011, 2:31pm UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/12 "2011-03-01T14:31:18Z")

</div>

Thanks Shay, I'll download the update and give it a try!

On Feb 28, 2011 8:49pm, Shay Banon [shay.banon@elasticsearch.com](mailto:shay.banon@elasticsearch.com) wrote:

> Heya,

> Several problems with the search request (the json is malformed). But, in  
> any case, this did not work properly. Here is a gist of an example of how  
> it should work: [gist:848506 · GitHub](https://gist.github.com/848506), and support for that has  
> been pushed to master  
> ([Search: Allow to use has\_child filter in facets · Issue #730 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/730)).

> -shay.banon

> On Monday, February 28, 2011 at 11:28 PM, [purplegherkin@gmail.com](mailto:purplegherkin@gmail.com) wrote:

> Sorry, that should have read: [facet has\_child error example · GitHub](https://gist.github.com/847657)

> On Feb 28, 2011 11:23am, [purplegherkin@gmail.com](mailto:purplegherkin@gmail.com) wrote:
> 
> > Shay,
> > 
> > Here ya go: git://gist.github.com/847657.git
> > 
> > thanks for taking a look!
> > 
> > Matt

---

<div class="post-metadata">

### Author: ![Matt\_Paul\_2](https://avatars.discourse-cdn.com/v4/letter/m/f19dbf/32.png) [@Matt\_Paul\_2](https://discuss.elastic.co/u/Matt_Paul_2)
#### Post date: [March 1, 2011, 9:05pm UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/13 "2011-03-01T21:05:12Z")

</div>

Shay,

I just tested it all, works like a champ now, thanks!

Matt

---

<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, 4:11am UTC](https://discuss.elastic.co/t/has-child-in-facet/3977/14 "2017-07-06T04:11:11Z")

</div>


