Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fancy/efficient way of checking if a document exists at elasticsearch

What is the most efficient way oof testing if a document with an _id exists?

I could obviously do:

curl -XGET localhost:9200/my_index/my_doctype/<_id>?fields=_id'.

Or I could go with: How do I check for duplicate data on ElasticSearch? and send an empty document, I guess.

Anything more efficient?

like image 723
eran Avatar asked Jun 12 '13 06:06

eran


1 Answers

You can use the HTTP HEAD verb to retrieve the headers only.

curl -XHEAD --dump-header - localhost:9200/index/type/doc

It will provide you with either 200 or 404 without any part of the document body.

like image 199
Louis-Philippe Huberdeau Avatar answered Oct 14 '22 17:10

Louis-Philippe Huberdeau