Clear cache

Introduced 1.0

The clear cache API operation clears the caches of one or more indexes. For data streams, the API clears the caches of the stream’s backing indexes.

If you use the Security plugin, you must have the manage index privileges.

Path and HTTP methods

  1. POST /<target>/_cache/clear

Path parameters

ParameterData typeDescription
targetStringComma-delimited list of data streams, indexes, and index aliases to which cache clearing is applied. Wildcard expressions () are supported. To target all data streams and indexes in a cluster, omit this parameter or use _all or . Optional.

Query parameters

All query parameters are optional.

ParameterData typeDescription
allow_no_indicesBooleanWhether to ignore wildcards, index aliases, or _all target (target path parameter) values that don’t match any indexes. If false, the request returns an error if any wildcard expression, index alias, or _all target value doesn’t match any indexes. This behavior also applies if the request targets include other open indexes. For example, a request where the target is fig,app returns an error if an index starts with fig but no index starts with app. Defaults to true.
expand_wildcardsStringDetermines the index types that wildcard expressions can expand to. Accepts multiple values separated by a comma, such as open,hidden. Valid values are:

all – Expand to open, closed, and hidden indexes.

open – Expand only to open indexes.

closed – Expand only to closed indexes

hidden – Expand to include hidden indexes. Must be combined with open, closed, or both.

none – Expansions are not accepted.

Defaults to open.
fielddataBooleanIf true, clears the fields cache. Use the fields parameter to clear specific fields’ caches. Defaults to true.
fieldsStringUsed in conjunction with the fielddata parameter. Comma-delimited list of field names that are cleared out of the cache. Does not support objects or field aliases. Defaults to all fields.
fileBooleanIf true, clears the unused entries from the file cache on nodes with the Search role. Defaults to false.
indexStringComma-delimited list of index names that are cleared out of the cache.
ignore_unavailableBooleanIf true, OpenSearch ignores missing or closed indexes. Defaults to false.
queryBooleanIf true, clears the query cache. Defaults to true.
requestBooleanIf true, clears the request cache. Defaults to true.

Example requests

The following example requests show multiple clear cache API uses.

Clear a specific cache

The following request clears the fields cache only:

  1. POST /my-index/_cache/clear?fielddata=true

copy


The following request clears the query cache only:

  1. POST /my-index/_cache/clear?query=true

copy


The following request clears the request cache only:

  1. POST /my-index/_cache/clear?request=true

copy

Clear the cache for specific fields

The following request clears the fields caches of fielda and fieldb:

  1. POST /my-index/_cache/clear?fields=fielda,fieldb

copy

Clear caches for specific data streams or indexes

The following request clears the cache for two specific indexes:

  1. POST /my-index,my-index2/_cache/clear

copy

Clear caches for all data streams and indexes

The following request clears the cache for all data streams and indexes:

  1. POST /_cache/clear

copy

Clear unused entries from the cache on search-capable nodes

  1. POST /*/_cache/clear?file=true

copy

Example response

The POST /books,hockey/_cache/clear request returns the following fields:

  1. {
  2. "_shards" : {
  3. "total" : 4,
  4. "successful" : 2,
  5. "failed" : 0
  6. }
  7. }

Response body fields

The POST /books,hockey/_cache/clear request returns the following response fields:

FieldData typeDescription
_shardsObjectShard information.
totalIntegerTotal number of shards.
successfulIntegerNumber of index shards with caches successfully cleared.
failedIntegerNumber of index shards with caches that failed to clear.