Hi Iv, You’d need to specify both parent and routing when you index grand children. See http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/grandparents.html
Masaru On January 15, 2015 at 20:44:43, Iv Igi (sayon...@gmail.com) wrote: > I am experiencing an issue while trying to retrieve a grandchild record by > its parent ID. (child-grandchild relationship) > The amount of hits in result is always zero. > Also the same request is working fine for parent-child relationship. > > My records are getting organized kinda like this: > > Account --(one to one)--> User --(one to one)--> Address > > My execution environment is: > - Fedora 21 CE > - openjdk 1.8.0_25 > - ES 1.4.2 > > Here is a script that is showing the problem > > # index creation > curl -XPUT "localhost:9200/the_index/" -d "{ > \"mappings\": { > \"account\" : {}, > \"user\" : { > \"_parent\" : { > \"type\" : \"account\" > } > }, > \"address\" : { > \"_parent\" : { > \"type\" : \"user\" > } > } > } > }"; > > # mrsmith account creation > curl -XPUT "localhost:9200/the_index/account/mrsmith" -d "{ > \"foo\" : \"foo\" > }"; > > # john user creation > curl -XPUT "localhost:9200/the_index/user/john?parent=mrsmith" -d "{ > \"bar\" : \"bar\" > }"; > > # john user creation > curl -XPUT "localhost:9200/the_index/address/smithshouse?parent=john" -d "{ > \"baz\" : \"baz\" > }"; > > # Here I am trying to retrieve a record. Getting zero hits. > curl -XGET "localhost:9200/the_index/address/_search?pretty" -d "{ > \"query\" : { \"bool\" : { \"must\" : { \"term\" : { \"_parent\" : > \"john\" } } } } > }"; > > # Another approach with has_parent query type. Still getting zero hits. > curl -XGET "localhost:9200/the_index/address/_search?pretty" -d "{ > \"query\" : { > \"has_parent\" : { > \"parent_type\" : \"user\", > \"query\" : { > \"term\" : { > \"_id\" : \"john\" > } > } > } > } > }"; > > # OK, lets try a routed search. Nope > curl -XGET "localhost:9200/the_index/address/_search?routing=john&pretty" > -d "{ > \"query\" : { \"bool\" : { \"must\" : { \"term\" : { \"_parent\" : > \"john\" } } } } > }"; > > # Routed has_parent query. Same > curl -XGET "localhost:9200/the_index/address/_search?routing=john&pretty" > -d "{ > \"query\" : { > \"has_parent\" : { > \"parent_type\" : \"user\", > \"query\" : { > \"term\" : { > \"_id\" : \"john\" > } > } > } > } > }"; > > # Retrieving a record by itself. Going just fine. > curl -XGET "localhost:9200/the_index/address/smithshouse?parent=john"; > > # Querying for user record with the same query. Got a hit. > curl -XGET "localhost:9200/the_index/user/_search?pretty" -d "{ > \"query\" : { \"bool\" : { \"must\" : { \"term\" : { \"_parent\" : > \"mrsmith\" } } } } > }"; > > > > The output: > > {"acknowledged":true} > {"_index":"the_index","_type":"account","_id":"mrsmith","_version":1,"created":true}{"_index":"the_index","_type":"user","_id":"john","_version":1,"created":true}{"_index":"the_index","_type":"address","_id":"smithshouse","_version":1,"created":true} > > { > "took" : 54, > "timed_out" : false, > "_shards" : { > "total" : 5, > "successful" : 5, > "failed" : 0 > }, > "hits" : { > "total" : 0, > "max_score" : null, > "hits" : [ ] > } > } > { > "took" : 221, > "timed_out" : false, > "_shards" : { > "total" : 5, > "successful" : 5, > "failed" : 0 > }, > "hits" : { > "total" : 0, > "max_score" : null, > "hits" : [ ] > } > } > { > "took" : 35, > "timed_out" : false, > "_shards" : { > "total" : 1, > "successful" : 1, > "failed" : 0 > }, > "hits" : { > "total" : 0, > "max_score" : null, > "hits" : [ ] > } > } > { > "took" : 481, > "timed_out" : false, > "_shards" : { > "total" : 1, > "successful" : 1, > "failed" : 0 > }, > "hits" : { > "total" : 0, > "max_score" : null, > "hits" : [ ] > } > } > {"_index":"the_index","_type":"address","_id":"smithshouse","_version":1,"found":true,"_source":{ > > "baz" : "baz" > }} > { > "took" : 65, > "timed_out" : false, > "_shards" : { > "total" : 5, > "successful" : 5, > "failed" : 0 > }, > "hits" : { > "total" : 1, > "max_score" : 1.0, > "hits" : [ { > "_index" : "the_index", > "_type" : "user", > "_id" : "john", > "_score" : 1.0, > "_source":{ > "bar" : "bar" > } > } ] > } > } > > You can find out on resuls that ES got the required shard, but no records > have been fetched. > Probably I am doing it in a wrong way, and if it so please fix me up. > > -- > You received this message because you are subscribed to the Google Groups > "elasticsearch" > group. > To unsubscribe from this group and stop receiving emails from it, send an > email to elasticsearch+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/elasticsearch/bbaebc65-a87f-4857-a2a4-577b0b487c6b%40googlegroups.com. > > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/etPan.54b88def.46e87ccd.1877%40citra.local. For more options, visit https://groups.google.com/d/optout.