python: How to check if a document exist in Elasticsearch using a doc _id

Viewed 4298

Is there any way, through any of the pythonic Elasticsearch libraries, to check if a document exist in a given index using the _id field?

Say I have a random doc _id of 73H316Dhgh and I want to check if it exists on a given index? How would I go about this using either of the python Elasticsearch libraries?

1 Answers

You can use the get method to get the document:

es.get(index="my-index", id="73H316Dhgh")

Otherwise if you don't need the full document, but just check for existence, you can use the exists method:

es.exists(index="my-index", id="73H316Dhgh")
Related