0
0
Elasticsearchquery~5 mins

Cache management (query, request, field data) in Elasticsearch

Choose your learning style9 modes available
Introduction

Cache helps Elasticsearch find data faster by saving recent searches and results. Managing cache well keeps your searches quick and your system smooth.

When you want to speed up repeated searches on the same data.
When you notice slow search responses and want to improve performance.
When you want to control memory use by clearing old or unused cached data.
When you update data and want to make sure searches use fresh information.
When you want to understand how Elasticsearch stores and reuses search results.
Syntax
Elasticsearch
POST /_cache/clear
{
  "query": true,
  "fielddata": true,
  "request": true
}

This example shows how to clear different caches in Elasticsearch.

You can clear query cache, field data cache, or request cache separately or all at once.

Examples
This clears only the query cache for the index named my_index.
Elasticsearch
POST /my_index/_cache/clear
{
  "query": true
}
This clears only the field data cache, which stores data for sorting and aggregations.
Elasticsearch
POST /my_index/_cache/clear
{
  "fielddata": true
}
This clears the request cache, which stores results of frequent searches.
Elasticsearch
POST /my_index/_cache/clear
{
  "request": true
}
This clears all caches on all indices.
Elasticsearch
POST /_cache/clear
{
  "query": true,
  "fielddata": true,
  "request": true
}
Sample Program

This example first runs a search with request cache enabled, then clears the request cache for my_index.

Elasticsearch
POST /my_index/_search?request_cache=true
{
  "query": {
    "match": { "message": "hello" }
  }
}

# Then clear the request cache

POST /my_index/_cache/clear
{
  "request": true
}
OutputSuccess
Important Notes

Clearing cache can slow down searches temporarily because Elasticsearch must rebuild the cache.

Use cache clearing carefully in busy systems to avoid performance drops.

Request cache works best for repeated identical queries.

Summary

Cache stores recent search data to speed up Elasticsearch queries.

You can clear query, field data, or request caches separately.

Managing cache helps keep search fast and system stable.