[[doc-exists]] === Checking Whether a Document Exists
If all you want to do is to check whether a ((("documents", "checking whether a document exists")))document exists--you're not
interested in the content at all--then use((("HEAD method")))((("HTTP methods", "HEAD"))) the HEAD
method instead
of the GET
method. HEAD
requests don't return a body, just HTTP headers:
Elasticsearch will return a 200 OK
status code if the document exists:
HTTP/1.1 200 OK Content-Type: text/plain; charset=UTF-8
And a 404 Not Found
if it doesn't exist:
HTTP/1.1 404 Not Found Content-Type: text/plain; charset=UTF-8
Of course, just because a document didn't exist when you checked it, doesn't mean that it won't exist a millisecond later: another process might create the document in the meantime.