J.Done
J.Done

Reputation: 3053

Elasticsearch - get specific child documents

   question
    /    \
   /      \
comment  answer

If I have this document structure with join mapping (in elasticsearch 6.2.2).

{
  "query": {
    "has_parent": {
      "parent_type": "qustion",
      "query": {
        "term": {
          "no": "1"
        }
      }
    }
  }
}

I can get all comment&answer related to question no 1 with this query. What if I want to get ONLY answer document, How should I change this query?

Upvotes: 0

Views: 44

Answers (1)

aclowkay
aclowkay

Reputation: 3887

Simply add a condition

{
  "query": {
    "bool":{
        "must":[{"has_parent": {
            "parent_type": "qustion",
            "query": {
              "term": {
                "no": "1"
              }
            }
          }},{
              "type":"answer"
          }]
    }
  }
}

Upvotes: 1

Related Questions