# Parent-Child search

**URL:** <https://discuss.elastic.co/t/parent-child-search/3707>\
**Category:** Elasticsearch\
**Created:** [December 29, 2010, 9:58am UTC](https://discuss.elastic.co/t/parent-child-search/3707 "2010-12-29T09:58:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![senthil\_prabhu](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@senthil\_prabhu](https://discuss.elastic.co/u/senthil_prabhu)\
**Post date:** [December 29, 2010, 9:58am UTC](https://discuss.elastic.co/t/parent-child-search/3707/1 "2010-12-29T09:58:34Z")

</div>

Hi all... how to search in parent-child

1. Create a database with table name metadata

2.Insert the values for metadata table

```
$ curl -XPUT 'http://localhost:9200/dbparent/metadata/1' -d

```

'{ "user" : "senthil", "Title" : "trying out Elastic Search"}'  
$ curl -XPUT '[http://localhost:9200/dbparent/metadata/2](http://localhost:9200/dbparent/metadata/2)' -d  
'{ "user" : "kumar", "Title" : "Elastic Search"}'

3.Create a child table for dbparent database

```
$ curl -XPUT 'http://localhost:9200/dbparent/metadata/_mapping' -d

```

'{ "child" : { "\_parent" : { "type" :  
"metadata" } }}'

4.Insert values for child table

```
$ curl -XPUT 'http://localhost:9200/dbparent/child/1?parent=1' -d

```

'{ "tag" : "something"}'

5.After that i am searching the parent using the 'has\_child' query  
like below mentioned

```
$ curl -XGET 'http://192.168.0.12:9200/dbparent/_search' -d

```

'{ "has\_child" : {"type" : "child" "query" :{"term" : {"tag" :  
"something"}}}}'

```
but i am getting error while search like this..

$ curl -XGET 'http://localhost:9200/dbparent/_search' -d

```

'{ "has\_child" : {"type" : "child" "query" :{"term" : {"tag" :  
"something"}}}}'  
{"error":"SearchPhaseExecutionException[Failed to execute phase  
[query], total failure; shardFailures {[q2w-8AyzSl2Uq7i7sAUwXw]  
[dbparent][0]: SearchParseException[[dbparent][0]: from[-1],size[-1]:  
Parse Failure [Failed to parse source [{ "has\_child" : {"type" :  
"child" "query" :{"term" : {  
"tag" : "something"}}}}]]]; nested: SearchParseException[[dbparent]  
[0]: from[-1],size[-1]: Parse Failure [No parser for element  
[has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw][dbparent][1]:  
SearchParseException[[dbparent][1]: from[-1],size[-1]: Parse Failure  
[Failed to parse source [{ "has\_child" :  
{"type" : "child" "query" :{"term" : {"tag" : "something  
"}}}}]]]; nested: SearchParseException[[dbparent][1]:  
from[-1],size[-1]: Parse Failure [No parser for element  
[has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw][dbparent][2]:  
SearchParseException[[dbparent][2]: from[-1],size[-1]: Parse Failu  
re [Failed to parse source [{ "has\_child" : {"type" : "child"  
"query" :{"term" : {"tag" : "something"}}}}]]]; nested:  
SearchParseException[[dbparent][2]: from[-1],size[-1]: Parse Failure  
[No parser for element [has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw]  
[dbparent][3]: SearchParseException  
[[dbparent][3]: from[-1],size[-1]: Parse Failure [Failed to parse  
source [{ "has\_child" : {"type" : "child" "query" :{"term" :  
{"tag" : "something"}}}}]]]; nested:  
SearchParseException[[dbparent][3]: from[-1],size[-1]: Parse Failure  
[No parser for element [has\_child]]]; }{[q2w-8AyzSl2U  
q7i7sAUwXw][dbparent][4]: SearchParseException[[dbparent][4]:  
from[-1],size[-1]: Parse Failure [Failed to parse source [{ "has\_child  
" : {"type" : "child" "query" :{"term" : {"tag" :  
"something"}}}}]]]; nested: SearchParseException[[dbparent][4]:  
from[-1],size[-1]: Parse Failure [No par  
ser for element [has\_child]]]; }]"}

---

<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:** [December 29, 2010, 10:25am UTC](https://discuss.elastic.co/t/parent-child-search/3707/2 "2010-12-29T10:25:50Z")

</div>

Here is a gist of something that works: [gist:758398 · GitHub](https://gist.github.com/758398).

Two problems you made: the first is that you applied the child mapping on  
the metadata mapping, and the second that your search request did not  
include a top level query wrapper.

p.s. Please gist curl samples from now on, formatting and so on are not  
maintained on mail.

On Wed, Dec 29, 2010 at 11:58 AM, senthil prabhu [senthilsebi@gmail.com](mailto:senthilsebi@gmail.com)wrote:

> Hi all... how to search in parent-child
> 
> 1. Create a database with table name metadata
> 
> 2.Insert the values for metadata table
> 
> ```
> $ curl -XPUT 'http://localhost:9200/dbparent/metadata/1' -d
> 
> ```
> 
> '{ "user" : "senthil", "Title" : "trying out Elastic Search"}'  
> $ curl -XPUT '[http://localhost:9200/dbparent/metadata/2](http://localhost:9200/dbparent/metadata/2)' -d  
> '{ "user" : "kumar", "Title" : "Elastic Search"}'
> 
> 3.Create a child table for dbparent database
> 
> ```
> $ curl -XPUT 'http://localhost:9200/dbparent/metadata/_mapping' -d
> 
> ```
> 
> '{ "child" : { "\_parent" : { "type" :  
> "metadata" } }}'
> 
> 4.Insert values for child table
> 
> ```
> $ curl -XPUT 'http://localhost:9200/dbparent/child/1?parent=1' -d
> 
> ```
> 
> '{ "tag" : "something"}'
> 
> 5.After that i am searching the parent using the 'has\_child' query  
> like below mentioned
> 
> ```
> $ curl -XGET 'http://192.168.0.12:9200/dbparent/_search' -d
> 
> ```
> 
> '{ "has\_child" : {"type" : "child" "query" :{"term" : {"tag" :  
> "something"}}}}'
> 
> ```
> but i am getting error while search like this..
> 
> $ curl -XGET 'http://localhost:9200/dbparent/_search' -d
> 
> ```
> 
> '{ "has\_child" : {"type" : "child" "query" :{"term" : {"tag" :  
> "something"}}}}'  
> {"error":"SearchPhaseExecutionException[Failed to execute phase  
> [query], total failure; shardFailures {[q2w-8AyzSl2Uq7i7sAUwXw]  
> [dbparent][0]: SearchParseException[[dbparent][0]: from[-1],size[-1]:  
> Parse Failure [Failed to parse source [{ "has\_child" : {"type" :  
> "child" "query" :{"term" : {  
> "tag" : "something"}}}}]]]; nested: SearchParseException[[dbparent]  
> [0]: from[-1],size[-1]: Parse Failure [No parser for element  
> [has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw][dbparent][1]:  
> SearchParseException[[dbparent][1]: from[-1],size[-1]: Parse Failure  
> [Failed to parse source [{ "has\_child" :  
> {"type" : "child" "query" :{"term" : {"tag" : "something  
> "}}}}]]]; nested: SearchParseException[[dbparent][1]:  
> from[-1],size[-1]: Parse Failure [No parser for element  
> [has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw][dbparent][2]:  
> SearchParseException[[dbparent][2]: from[-1],size[-1]: Parse Failu  
> re [Failed to parse source [{ "has\_child" : {"type" : "child"  
> "query" :{"term" : {"tag" : "something"}}}}]]]; nested:  
> SearchParseException[[dbparent][2]: from[-1],size[-1]: Parse Failure  
> [No parser for element [has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw]  
> [dbparent][3]: SearchParseException  
> [[dbparent][3]: from[-1],size[-1]: Parse Failure [Failed to parse  
> source [{ "has\_child" : {"type" : "child" "query" :{"term" :  
> {"tag" : "something"}}}}]]]; nested:  
> SearchParseException[[dbparent][3]: from[-1],size[-1]: Parse Failure  
> [No parser for element [has\_child]]]; }{[q2w-8AyzSl2U  
> q7i7sAUwXw][dbparent][4]: SearchParseException[[dbparent][4]:  
> from[-1],size[-1]: Parse Failure [Failed to parse source [{ "has\_child  
> " : {"type" : "child" "query" :{"term" : {"tag" :  
> "something"}}}}]]]; nested: SearchParseException[[dbparent][4]:  
> from[-1],size[-1]: Parse Failure [No par  
> ser for element [has\_child]]]; }]"}

---

<div class="post-metadata">

**Author:** ![senthil\_prabhu](https://avatars.discourse-cdn.com/v4/letter/s/9e8a1a/32.png) [@senthil\_prabhu](https://discuss.elastic.co/u/senthil_prabhu)\
**Post date:** [December 29, 2010, 11:18am UTC](https://discuss.elastic.co/t/parent-child-search/3707/3 "2010-12-29T11:18:24Z")

</div>

Thank you its working fine now Shay Banon......

On Dec 29, 3:25 pm, Shay Banon [shay.ba...@elasticsearch.com](mailto:shay.ba...@elasticsearch.com) wrote:

> Here is a gist of something that works:[gist:758398 · GitHub](https://gist.github.com/758398).
> 
> Two problems you made: the first is that you applied the child mapping on  
> the metadata mapping, and the second that your search request did not  
> include a top level query wrapper.
> 
> p.s. Please gist curl samples from now on, formatting and so on are not  
> maintained on mail.
> 
> On Wed, Dec 29, 2010 at 11:58 AM, senthil prabhu [senthils...@gmail.com](mailto:senthils...@gmail.com)wrote:
> 
> > Hi all... how to search in parent-child
> 
> > 1. Create a database with table name metadata
> 
> > ```
> > $ curl -XPUT 'http://localhost:9200/dbparent'
> > 
> > ```
> 
> > 2.Insert the values for metadata table
> 
> > ```
> > $ curl -XPUT 'http://localhost:9200/dbparent/metadata/1' -d
> > 
> > ```
> > 
> > '{ "user" : "senthil", "Title" : "trying out Elastic Search"}'  
> > $ curl -XPUT '[http://localhost:9200/dbparent/metadata/2](http://localhost:9200/dbparent/metadata/2)' -d  
> > '{ "user" : "kumar", "Title" : "Elastic Search"}'
> 
> > 3.Create a child table for dbparent database
> 
> > ```
> > $ curl -XPUT 'http://localhost:9200/dbparent/metadata/_mapping'-d
> > 
> > ```
> > 
> > '{ "child" : { "\_parent" : { "type" :  
> > "metadata" } }}'
> 
> > 4.Insert values for child table
> 
> > ```
> > $ curl -XPUT 'http://localhost:9200/dbparent/child/1?parent=1'-d
> > 
> > ```
> > 
> > '{ "tag" : "something"}'
> 
> > 5.After that i am searching the parent using the 'has\_child' query  
> > like below mentioned
> 
> > ```
> > $ curl -XGET 'http://192.168.0.12:9200/dbparent/_search'-d
> > 
> > ```
> > 
> > '{ "has\_child" : {"type" : "child" "query" :{"term" : {"tag" :  
> > "something"}}}}'
> 
> > ```
> > but i am getting error while search like this..
> > 
> > ```
> 
> > ```
> > $ curl -XGET 'http://localhost:9200/dbparent/_search'-d
> > 
> > ```
> > 
> > '{ "has\_child" : {"type" : "child" "query" :{"term" : {"tag" :  
> > "something"}}}}'  
> > {"error":"SearchPhaseExecutionException[Failed to execute phase  
> > [query], total failure; shardFailures {[q2w-8AyzSl2Uq7i7sAUwXw]  
> > [dbparent][0]: SearchParseException[[dbparent][0]: from[-1],size[-1]:  
> > Parse Failure [Failed to parse source [{ "has\_child" : {"type" :  
> > "child" "query" :{"term" : {  
> > "tag" : "something"}}}}]]]; nested: SearchParseException[[dbparent]  
> > [0]: from[-1],size[-1]: Parse Failure [No parser for element  
> > [has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw][dbparent][1]:  
> > SearchParseException[[dbparent][1]: from[-1],size[-1]: Parse Failure  
> > [Failed to parse source [{ "has\_child" :  
> > {"type" : "child" "query" :{"term" : {"tag" : "something  
> > "}}}}]]]; nested: SearchParseException[[dbparent][1]:  
> > from[-1],size[-1]: Parse Failure [No parser for element  
> > [has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw][dbparent][2]:  
> > SearchParseException[[dbparent][2]: from[-1],size[-1]: Parse Failu  
> > re [Failed to parse source [{ "has\_child" : {"type" : "child"  
> > "query" :{"term" : {"tag" : "something"}}}}]]]; nested:  
> > SearchParseException[[dbparent][2]: from[-1],size[-1]: Parse Failure  
> > [No parser for element [has\_child]]]; }{[q2w-8AyzSl2Uq7i7sAUwXw]  
> > [dbparent][3]: SearchParseException  
> > [[dbparent][3]: from[-1],size[-1]: Parse Failure [Failed to parse  
> > source [{ "has\_child" : {"type" : "child" "query" :{"term" :  
> > {"tag" : "something"}}}}]]]; nested:  
> > SearchParseException[[dbparent][3]: from[-1],size[-1]: Parse Failure  
> > [No parser for element [has\_child]]]; }{[q2w-8AyzSl2U  
> > q7i7sAUwXw][dbparent][4]: SearchParseException[[dbparent][4]:  
> > from[-1],size[-1]: Parse Failure [Failed to parse source [{ "has\_child  
> > " : {"type" : "child" "query" :{"term" : {"tag" :  
> > "something"}}}}]]]; nested: SearchParseException[[dbparent][4]:  
> > from[-1],size[-1]: Parse Failure [No par  
> > ser for element [has\_child]]]; }]"}

---

<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:14am UTC](https://discuss.elastic.co/t/parent-child-search/3707/4 "2017-07-06T04:14:43Z")

</div>


