[[indices-clearcache]]
=== Clear cache API
++++
<titleabbrev>Clear cache</titleabbrev>
++++

Clears the caches of one or more indices. For data streams, the API clears the
caches of the stream's backing indices.

[source,console]
----
POST /my-index-000001/_cache/clear
----
// TEST[setup:my_index]


[[clear-cache-api-request]]
==== {api-request-title}

`POST /<target>/_cache/clear`

`POST /_cache/clear`

[[clear-cache-api-prereqs]]
==== {api-prereq-title}

* If the {es} {security-features} are enabled, you must have the `manage`
<<privileges-list-indices,index privilege>> for the target data stream, index,
or alias.

[[clear-cache-api-path-params]]
==== {api-path-parms-title}

`<target>`::
(Optional, string) Comma-separated list of data streams, indices, and aliases
used to limit the request. Supports wildcards (`*`). To target all data streams
and indices, omit this parameter or use `*` or `_all`.

[[clear-cache-api-query-params]]
==== {api-query-parms-title}

include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=allow-no-indices]
+
Defaults to `true`.

include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=expand-wildcards]
+
Defaults to `open`.

`fielddata`::
+
--
(Optional, Boolean)
If `true`,
clears the fields cache.

Use the `fields` parameter
to clear the cache of specific fields only.
--

`fields`::
+
--
(Optional, string)
Comma-separated list of field names
used to limit the `fielddata` parameter.

Defaults to all fields.

NOTE: This parameter does *not* support objects
or field aliases.
--


`index`::
(Optional, string)
Comma-separated list of index names
used to limit the request.

include::{es-repo-dir}/rest-api/common-parms.asciidoc[tag=index-ignore-unavailable]

`query`::
(Optional, Boolean)
If `true`,
clears the query cache.

`request`::
(Optional, Boolean)
If `true`,
clears the request cache.


[[clear-cache-api-example]]
==== {api-examples-title}


[[clear-cache-api-specific-ex]]
===== Clear a specific cache

By default,
the clear cache API clears all caches.
You can clear only specific caches
by setting the following query parameters to `true`:

* `fielddata`
* `query`
* `request`

[source,console]
----
POST /my-index-000001/_cache/clear?fielddata=true  <1>
POST /my-index-000001/_cache/clear?query=true      <2>
POST /my-index-000001/_cache/clear?request=true    <3>
----
// TEST[continued]

<1> Clears only the fields cache
<2> Clears only the query cache
<3> Clears only the request cache



[[clear-cache-api-specific-fields-ex]]
===== Clear the cache of specific fields

To only clear the cache of specific fields,
use the `fields` query parameter.

[source,console]
----
POST /my-index-000001/_cache/clear?fields=foo,bar   <1>
----
// TEST[continued]

<1> Clear the cache for the `foo` and `bar` field


[[clear-cache-api-multi-ex]]
===== Clear caches for several data streams and indices

[source,console]
----
POST /my-index-000001,my-index-000002/_cache/clear
----
// TEST[s/^/PUT my-index-000001\nPUT my-index-000002\n/]


[[clear-cache-api-all-ex]]
===== Clear caches for all data streams and indices

[source,console]
----
POST /_cache/clear
----
