0
0
Elasticsearchquery~5 mins

Exists query in Elasticsearch

Choose your learning style9 modes available
Introduction

The Exists query helps you find documents that have a specific field filled in. It ignores documents where that field is missing.

You want to find all users who have provided their email address.
You want to list products that have a price set.
You want to filter blog posts that have an image attached.
You want to check which orders have a tracking number recorded.
Syntax
Elasticsearch
{
  "query": {
    "exists": {
      "field": "your_field_name"
    }
  }
}

Replace your_field_name with the exact name of the field you want to check.

This query returns documents where the field exists and is not null.

Examples
Finds all documents where the email field exists.
Elasticsearch
{
  "query": {
    "exists": {
      "field": "email"
    }
  }
}
Finds all documents where the price field exists.
Elasticsearch
{
  "query": {
    "exists": {
      "field": "price"
    }
  }
}
Sample Program

This query will return all documents that have a username field filled in.

Elasticsearch
{
  "query": {
    "exists": {
      "field": "username"
    }
  }
}
OutputSuccess
Important Notes

The exists query only checks if the field is present and not null.

If a field is an empty string or empty array, it still counts as existing.

Summary

The Exists query finds documents with a specific field present.

Use it to filter out documents missing important information.

It is simple and useful for many search filters.