Fenec
Fenec

Reputation: 1222

Return list of not matched ids in Elasticsearch query

I want to return the list of ids that don't have match in the index.

i.e I have this query:

{
    "ids" : {
        "values" : ["1", "4", "100"]
    }
}

Say, I have only record with _id 1 in index, thus the result gives me 1. What I want instead is to have ["4", "100"] (those that not presented in index) as the result. Is it possible somehow?

Upvotes: 1

Views: 1134

Answers (2)

Fenec
Fenec

Reputation: 1222

Ok, figured it out. I have to use multi-get API: https://www.elastic.co/guide/en/elasticsearch/guide/current/_retrieving_multiple_documents.html which returns "found": false for the documents that weren't found.

Upvotes: 2

Adonis
Adonis

Reputation: 4818

You can use must_not in a query to obtain documents that do not meet a criteria

Upvotes: 1

Related Questions