Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Check if document exists or not in elasticsearch

I want to check if a document with specific field value does exist or not in elasticsearch.

I have gone through internet but only found how to check if a field exists or not.

My Index/Type is

/twitter/user

username is one field in document.

I want to check if username="xyz" exists or not in this Type.

like image 243
Sagar Vaghela Avatar asked Aug 01 '17 10:08

Sagar Vaghela


1 Answers

You can query with size 0. total value will give you an idea that doc exists or not.

GET /twitter/user/_search
{"size": 0,
  "query": {"match": {
  "username": "xyz"
}}}

Edited --

_count api can be used as well.

GET /twitter/user/_count
{ "query": {"match": {
  "username": "xyz"
}}}
like image 128
xrage Avatar answered Oct 14 '22 06:10

xrage