Elasticsearch children-father issue with 'has_parent' -


having following mapping...

curl -xput 'localhost:9200/myindex' -d '{   "mappings": {     "my_parent": {},     "my_child": {       "_parent": {         "type": "my_parent"  }}}}' 

... following parent:

curl -x put localhost:9200/myindex/my_parent/1?pretty=true' -d '{   "title" : "microsiervos - discos duros de 10tb",   "body" : "empiezan sacar dd de 30gb en el mercado" }' 

and following children:

curl -xput 'localhost:9200/myindex/my_child/2?parent=1' -d '{   "user": "pepe" }' 

if following has_child query:

curl -xget 'localhost:9200/myindex/my_parent/_search?pretty=true' -d '{   "query": {     "has_child": {        "type": "my_child",       "query" : {            "query_string" : {                "default_field" : "user",                "query" : "pepe" }}}}}' 

i desired output. pepe found, , father shown:

  "hits" : {     "total" : 1,     "max_score" : 1.0,     "hits" : [ {       "_index" : "myindex",       "_type" : "my_parent",       "_id" : "2",       "_score" : 1.0,       "_source":{   "title" : "microsiervos - en el 69 llegamos la luna",   "body" : "se cumplen 3123 anos de la llegada la luna" } 

but if try in reverse trying children using has_parent:

curl -xget 'localhost:9200/myindex/my_parent/_search?pretty=true' -d '{   "query": {     "has_parent": {        "parent_type": "my_parent",       "query" : {            "query_string" : {                "default_field" : "body",                "query" : "mercado" }}}}}' 

i dont hits. supposing pepe children output. i'm missing or doing wrong?

ps: i'm using elasticsearch 2.1.1

you have made mistake above.you searching in my_parent type. if want fetch children using parent, should fetch child_type. change query to:

curl -xget 'localhost:9200/myindex/my_child/_search?pretty=true' -d       '{ "query": { "has_parent": {    "parent_type": "my_parent",   "query" : {        "query_string" : {            "default_field" : "body",            "query" : "mercado"       }     }   }  } }' 

please note have used

curl -xget 'localhost:9200/myindex/my_child/_search?pretty=true'  

instead of

curl -xget 'localhost:9200/myindex/my_parent/_search?pretty=true' 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -