# Parent/child queries are broken?

**URL:** https://discuss.elastic.co/t/parent-child-queries-are-broken/9762
**Category:** Elasticsearch
**Created:** [November 19, 2012, 4:34pm UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762 "2012-11-19T16:34:03Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)
#### Post date: [November 19, 2012, 4:34pm UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/1 "2012-11-19T16:34:03Z")

</div>

This seems broken in 0.19.\*. I had a working parent/child solution even  
before the new has\_child/has\_parent filters were implemented (see:  
[http://stackoverflow.com/questions/7431889/how-can-i-retrieve-matching-children-only](http://stackoverflow.com/questions/7431889/how-can-i-retrieve-matching-children-only))  
and now it doesn't work anymore.

I thought that maybe my indexes went awry, but deleting them and creating  
from scratch is not a problem for me, so I did that... And it did not help.

Suprised by the outcome I tried to run the queries with authors and books  
from this blog post -  
[http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/-](http://www.spacevatican.org/2012/6/3/fun-with-elasticsearch-s-children-and-nested-documents/-) just to try something very simple. So I have a dynamic (auto) mapping for  
the author, a manual mapping for the book (which specifies that author is  
the parent) and then added those two authors and three books. Then tried  
running the query to retrieve all books by an author, I tried both  
has\_child and has\_parent and they return 0 results. There is no error of  
any kind, just 0 results. Always. And in my old solution it started  
complaining about not being able to parse parent or \_parent.

Could somebody take a look and run the same queries against your  
ElasticSearch and tell me if parent/child queries work for you? I'll copy  
the steps below:

curl -XPUT localhost:9200/authors/bare\_author/1 -d'{ "name": "Multi G. Enre"  
}' curl -XPUT localhost:9200/authors/bare\_author/2 -d'{ "name": "Alastair  
Reynolds" }'

curl -XPOST localhost:9200/authors/book/\_mapping -d '{ "book":{ "\_parent": {  
"type": "bare\_author"} } }'

curl -XPOST localhost:9200/authors/book/1?parent=2 -d '{ "name": "Revelation  
Space", "genre": "scifi", "publisher": "penguin" }' curl -XPOST localhost:  
9200/authors/book/2?parent=1 -d '{ "name": "Guns and lasers", "genre":  
"scifi", "publisher": "orbit" }' curl -XPOST localhost:9200/authors/book/3  
?parent=1 -d '{ "name": "Dead in the night", "genre": "thriller",  
"publisher": "penguin" }'

curl -XPOST localhost:9200/authors/bare\_author/\_search -d '{ "query": {  
"has\_child": { "type": "book", "query" : { "filtered": { "query": {  
"match\_all": {}}, "filter" : { "and": [ {"term": {"publisher": "penguin"}},  
{"term": {"genre": "scifi"}} ] } } } } } }'

The last query should return all science fiction books published by  
Penguin. It doesn't return anything. The query below should find all books  
written by _Multi G. Enre_, again - it returns nothing (0 results):

curl -XGET localhost:9200/authors/book/\_search -d '{  
"query": "has\_parent": "parent\_type": "bare\_author", "query": "term":  
"name": "Multi G. Enre" } } } } }'

What's going on? ☹

--

---

<div class="post-metadata">

### Author: ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)
#### Post date: [November 19, 2012, 4:35pm UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/2 "2012-11-19T16:35:37Z")

</div>

The last query should of course return all books written by _Multi G. Enre_,  
Google cut my text (probably formatting issue).

--

---

<div class="post-metadata">

### Author: ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)
#### Post date: [November 19, 2012, 5:22pm UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/3 "2012-11-19T17:22:53Z")

</div>

Hi,

Do you think you can prepare gist with curl commands (aka recreation) and  
specify version of ES used in test? That can help.

Regards,  
Lukáš  
Dne 19.11.2012 17:35 "Paweł Krakowiak" [pawel.krakowiak@gmail.com](mailto:pawel.krakowiak@gmail.com)  
napsal(a):

> The last query should of course return all books written by \*Multi G. Enre  
> \*, Google cut my text (probably formatting issue).
> 
> --

--

---

<div class="post-metadata">

### Author: ![Chris\_Male](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/chris_male/32/2607_2.png) [@Chris\_Male](https://discuss.elastic.co/u/Chris_Male)
#### Post date: [November 20, 2012, 3:28am UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/4 "2012-11-20T03:28:33Z")

</div>

Additionally include your mapping if you can.

On Tuesday, November 20, 2012 6:23:03 AM UTC+13, Lukáš Vlček wrote:

> Hi,
> 
> Do you think you can prepare gist with curl commands (aka recreation) and  
> specify version of ES used in test? That can help.
> 
> Regards,  
> Lukáš  
> Dne 19.11.2012 17:35 "Paweł Krakowiak" \<[pawel.k...@gmail.com](mailto:pawel.k...@gmail.com) \<javascript:\>\>  
> napsal(a):
> 
> > The last query should of course return all books written by _Multi G.  
> > Enre_, Google cut my text (probably formatting issue).
> > 
> > --

--

---

<div class="post-metadata">

### Author: ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)
#### Post date: [November 20, 2012, 8:03am UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/5 "2012-11-20T08:03:09Z")

</div>

I don't know how a gist would help since it's the same text I pasted above  
:), but here you go [https://gist.github.com/4116598](https://gist.github.com/4116598). My original post  
contains all commands that are required to repeat the test. I am running  
the newest Elasticsearch 0.19.11 but it did not work in 0.19.10 either, not  
sure about earlier.

The mapping is also included in my original post - there's an explicit  
mapping for the books only, authors get mapped dynamically when the first  
author is added.

All I'm asking is for somebody to copy the commands that I provided and run  
them against their ES. If you don't get any results that would mean that ES  
has a bug.

W dniu wtorek, 20 listopada 2012 04:28:33 UTC+1 użytkownik Chris Male  
napisał:

> Additionally include your mapping if you can.
> 
> On Tuesday, November 20, 2012 6:23:03 AM UTC+13, Lukáš Vlček wrote:
> 
> > Hi,
> > 
> > Do you think you can prepare gist with curl commands (aka recreation) and  
> > specify version of ES used in test? That can help.
> > 
> > Regards,  
> > Lukáš  
> > Dne 19.11.2012 17:35 "Paweł Krakowiak" [pawel.k...@gmail.com](mailto:pawel.k...@gmail.com) napsal(a):
> > 
> > > The last query should of course return all books written by _Multi G.  
> > > Enre_, Google cut my text (probably formatting issue).
> > > 
> > > --

--

---

<div class="post-metadata">

### Author: ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)
#### Post date: [November 20, 2012, 8:04am UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/6 "2012-11-20T08:04:16Z")

</div>

My 0.19.11 ES is running on OS X (installed from Homebrew). I just ran the  
same test on an older 0.19.2 release on Windows and it works...

W dniu wtorek, 20 listopada 2012 09:03:09 UTC+1 użytkownik Paweł Krakowiak  
napisał:

> I don't know how a gist would help since it's the same text I pasted above  
> :), but here you go [https://gist.github.com/4116598](https://gist.github.com/4116598). My original post  
> contains all commands that are required to repeat the test. I am running  
> the newest Elasticsearch 0.19.11 but it did not work in 0.19.10 either, not  
> sure about earlier.
> 
> The mapping is also included in my original post - there's an explicit  
> mapping for the books only, authors get mapped dynamically when the first  
> author is added.
> 
> All I'm asking is for somebody to copy the commands that I provided and  
> run them against their ES. If you don't get any results that would mean  
> that ES has a bug.
> 
> W dniu wtorek, 20 listopada 2012 04:28:33 UTC+1 użytkownik Chris Male  
> napisał:
> 
> > Additionally include your mapping if you can.
> > 
> > On Tuesday, November 20, 2012 6:23:03 AM UTC+13, Lukáš Vlček wrote:
> > 
> > > Hi,
> > > 
> > > Do you think you can prepare gist with curl commands (aka recreation)  
> > > and specify version of ES used in test? That can help.
> > > 
> > > Regards,  
> > > Lukáš  
> > > Dne 19.11.2012 17:35 "Paweł Krakowiak" [pawel.k...@gmail.com](mailto:pawel.k...@gmail.com) napsal(a):
> > > 
> > > > The last query should of course return all books written by _Multi G.  
> > > > Enre_, Google cut my text (probably formatting issue).
> > > > 
> > > > --

--

---

<div class="post-metadata">

### Author: ![Pawel\_Krakowiak](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pawel_krakowiak/32/2615_2.png) [@Pawel\_Krakowiak](https://discuss.elastic.co/u/Pawel_Krakowiak)
#### Post date: [November 20, 2012, 9:03am UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/7 "2012-11-20T09:03:04Z")

</div>

I tried with 0.19.3 on OS X, it doesn't work either. Running the attached  
bash script. It runs OK, just doesn't return any results. ☹

W dniu wtorek, 20 listopada 2012 09:04:16 UTC+1 użytkownik Paweł Krakowiak  
napisał:

> My 0.19.11 ES is running on OS X (installed from Homebrew). I just ran the  
> same test on an older 0.19.2 release on Windows and it works...
> 
> W dniu wtorek, 20 listopada 2012 09:03:09 UTC+1 użytkownik Paweł Krakowiak  
> napisał:
> 
> > I don't know how a gist would help since it's the same text I pasted  
> > above :), but here you go [https://gist.github.com/4116598](https://gist.github.com/4116598). My original  
> > post contains all commands that are required to repeat the test. I am  
> > running the newest Elasticsearch 0.19.11 but it did not work in 0.19.10  
> > either, not sure about earlier.
> > 
> > The mapping is also included in my original post - there's an explicit  
> > mapping for the books only, authors get mapped dynamically when the first  
> > author is added.
> > 
> > All I'm asking is for somebody to copy the commands that I provided and  
> > run them against their ES. If you don't get any results that would mean  
> > that ES has a bug.
> > 
> > W dniu wtorek, 20 listopada 2012 04:28:33 UTC+1 użytkownik Chris Male  
> > napisał:
> > 
> > > Additionally include your mapping if you can.
> > > 
> > > On Tuesday, November 20, 2012 6:23:03 AM UTC+13, Lukáš Vlček wrote:
> > > 
> > > > Hi,
> > > > 
> > > > Do you think you can prepare gist with curl commands (aka recreation)  
> > > > and specify version of ES used in test? That can help.
> > > > 
> > > > Regards,  
> > > > Lukáš  
> > > > Dne 19.11.2012 17:35 "Paweł Krakowiak" [pawel.k...@gmail.com](mailto:pawel.k...@gmail.com)  
> > > > napsal(a):
> > > > 
> > > > > The last query should of course return all books written by _Multi G.  
> > > > > Enre_, Google cut my text (probably formatting issue).
> > > > > 
> > > > > --

--

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [November 20, 2012, 12:49pm UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/8 "2012-11-20T12:49:00Z")

</div>

Your gist is missing \_refresh (curl -XPOST  
localhost:9200/authors/\_refresh) before \_search, which means that records  
might not be indexed yet when you run search for the first time. After  
adding \_refresh everything seem to work. I get one record back as  
expected. I tried it with 0.19.3 and 0.19.11 on OS X.

On Tuesday, November 20, 2012 4:03:04 AM UTC-5, Paweł Krakowiak wrote:

> I tried with 0.19.3 on OS X, it doesn't work either. Running the attached  
> bash script. It runs OK, just doesn't return any results. ☹
> 
> W dniu wtorek, 20 listopada 2012 09:04:16 UTC+1 użytkownik Paweł Krakowiak  
> napisał:
> 
> > My 0.19.11 ES is running on OS X (installed from Homebrew). I just ran  
> > the same test on an older 0.19.2 release on Windows and it works...
> > 
> > W dniu wtorek, 20 listopada 2012 09:03:09 UTC+1 użytkownik Paweł  
> > Krakowiak napisał:
> > 
> > > I don't know how a gist would help since it's the same text I pasted  
> > > above :), but here you go [https://gist.github.com/4116598](https://gist.github.com/4116598). My  
> > > original post contains all commands that are required to repeat the test. I  
> > > am running the newest Elasticsearch 0.19.11 but it did not work in 0.19.10  
> > > either, not sure about earlier.
> > > 
> > > The mapping is also included in my original post - there's an explicit  
> > > mapping for the books only, authors get mapped dynamically when the first  
> > > author is added.
> > > 
> > > All I'm asking is for somebody to copy the commands that I provided and  
> > > run them against their ES. If you don't get any results that would mean  
> > > that ES has a bug.
> > > 
> > > W dniu wtorek, 20 listopada 2012 04:28:33 UTC+1 użytkownik Chris Male  
> > > napisał:
> > > 
> > > > Additionally include your mapping if you can.
> > > > 
> > > > On Tuesday, November 20, 2012 6:23:03 AM UTC+13, Lukáš Vlček wrote:
> > > > 
> > > > > Hi,
> > > > > 
> > > > > Do you think you can prepare gist with curl commands (aka recreation)  
> > > > > and specify version of ES used in test? That can help.
> > > > > 
> > > > > Regards,  
> > > > > Lukáš  
> > > > > Dne 19.11.2012 17:35 "Paweł Krakowiak" [pawel.k...@gmail.com](mailto:pawel.k...@gmail.com)  
> > > > > napsal(a):
> > > > > 
> > > > > > The last query should of course return all books written by _Multi  
> > > > > > G. Enre_, Google cut my text (probably formatting issue).
> > > > > > 
> > > > > > --

--

---

<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, 3:03am UTC](https://discuss.elastic.co/t/parent-child-queries-are-broken/9762/9 "2017-07-06T03:03:33Z")

</div>


