Parent-Child search

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' -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]]]; }]"}

Here is a gist of something that works: gist:758398 · GitHub.

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.comwrote:

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' -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]]]; }]"}

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

On Dec 29, 3:25 pm, Shay Banon shay.ba...@elasticsearch.com wrote:

Here is a gist of something that works:gist:758398 · GitHub.

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.comwrote:

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' -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]]]; }]"}