Hi all... how to search in parent-child
-
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]]]; }]"}