Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find nested documents by id

Elasticsearch has ids query to find documents by id. I tried to use it in nested query:

{
    "query": {
        "nested": {
           "path": "nestedField",
           "query": {"ids":{ "values": ["nestedDocumentId" ] }},
           "inner_hits" : {}    
        } 
    }
}

But this query looks at parent document id, not at nested.
Can I use ids query for finding nested documents by their ids?

like image 929
Taras Kohut Avatar asked Jul 12 '16 12:07

Taras Kohut


1 Answers

The id of the nested documents is automatically created and you cannot control that.

The solution is to index that id in the nested document itslef as regular field and do a terms filter instead of ids.

like image 91
Andrei Stefan Avatar answered Sep 29 '22 02:09

Andrei Stefan