Taras Kohut
Taras Kohut

Reputation: 2555

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?

Upvotes: 5

Views: 2780

Answers (1)

Andrei Stefan
Andrei Stefan

Reputation: 52366

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.

Upvotes: 6

Related Questions