Ido Nadler
Ido Nadler

Reputation: 1

Retrieve all parent's children from Elasticsearch

I have a parent-child relationship and I am looking for a way to retrieve the children while searching on the parent.

In other words, I want to get all the posts of a user who's name is John.

I was trying to do the following but without any luck.

CRUD POST http://localhost/myIndex/user/_search  
{        
  "query": {  
    "bool": {
      name:"John",
      "has_child": {  
        "type": "post",  
        "query_all": {}  
      }
    }      
  }  
}   

Upvotes: 0

Views: 55

Answers (1)

alpert
alpert

Reputation: 4655

Try:

CRUD POST http://localhost/myIndex/post/_search  
{
  "query": {
    "has_parent": {
      "type": "user", 
      "query": {
        "match": {
          "name": "John"
        }
      }
    }
  }
}

Checkout: https://www.elastic.co/guide/en/elasticsearch/guide/current/has-parent.html

Upvotes: 1

Related Questions