I had partial success implementing parent child relation. I was able to 
create the mappings correctly (I presume), and post documents without any 
issue.
In the example below, "family" index has types "dad", "child", 
"grandchild". "child" has parent type as "dad", and "grandchild" has parent 
type "child".

While using "has_child" query, I could only get documents 1 level deep (dad 
to child), but not to the 2nd level (child to grandchild). See the last 
POST at the bottom that didn't return grandchild as expected.

   - Can you please review whats wrong here (if any) ?
   - Any idea on whats going on would be greatly appreciated!
   

*POST http://localhost:9200/family*
{
  "mappings": {
    "dad": {
      "properties": {
        "name": {
          "type": "string", "index": "not_analyzed"
        }
      }
    },
    "child": {
      "_parent": {
        "type": "dad"
      },
      "properties": {
        "name": {
          "type": "string", "index": "not_analyzed"
        }
      }
    },
    "grandchild": {
      "_parent": {
        "type": "child"
      },
      "properties": {
        "name": {
          "type": "string", "index": "not_analyzed"
        }
      }
    }
  }
}



*POST http://localhost:9200/family/dad/1*
{
  "name" : "Dad1"
}

*POST http://localhost:9200/family/child/10?parent=1*
{
  "name" : "Child1",
  "_parent" : "1"
}


*POST http://localhost:9200/family/grandchild/100?parent=10*
{
  "name" : "GrandChild1",
  "_parent" : "10"
}


*POST http://localhost:9200/family/dad/_search*
{
  "query" : {
    "has_child" : {
      "type" : "child",
      "query" : {
        "match" : {
          "name" : "Child1"
        }
      }
    }
  }
}

Response to the above POST:
{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 1,
        "max_score": 1,
        "hits": [
            {
                "_index": "family",
                "_type": "dad",
                "_id": "1",
                "_score": 1,
                "_source": {
                    "name": "Dad1"
                }
            }
        ]
    }
}


*POST http://localhost:9200/family/child/_search*
{
  "query" : {
    "has_child" : {
      "type" : "grandchild",
      "query" : {
        "match" : {
          "name" : "GrandChild1" 
        }
      }
    }
  }
}


Response to the above POST (it doesn't return "child" type with name 
"Child1"):
{
    "took": 2,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 0,
        "max_score": null,
        "hits": []
    }
}


-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/elasticsearch/d2cdb28d-1c8e-4054-b5a2-9d58cf811aa1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to