Skip to content

Commit 34d6028

Browse files
committed
shard request cache
1 parent b3b762e commit 34d6028

File tree

11 files changed

+631
-528
lines changed

11 files changed

+631
-528
lines changed

docs/reference/commands/node-tool.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ Unsafe cluster bootstrapping is only possible if there is at least one
309309
surviving master-eligible node. If there are no remaining master-eligible nodes
310310
then the cluster metadata is completely lost. However, the individual data
311311
nodes also contain a copy of the index metadata corresponding with their shards. This sometimes allows a new cluster to import these shards as
312-
<<dangling-indices-api,dangling indicesi>>. You can sometimes
312+
<<dangling-indices,dangling indices>>. You can sometimes
313313
recover some indices after the loss of all main-eligible nodes in a cluster
314314
by creating a new cluster and then using the `elasticsearch-node
315315
detach-cluster` command to move any surviving nodes into this new cluster. Once the new cluster is fully formed,

docs/reference/data-store-architecture.asciidoc

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@ from any node.
99
The topics in this section provides information about the architecture of {es} and how it stores and retrieves data:
1010

1111
* <<nodes-shards,Nodes and shards>>: Learn about the basic building blocks of an {es} cluster, including nodes, shards, primaries, and replicas.
12+
* <<node-roles-overview,Node roles>>: Learn about the different roles that nodes can have in an {es} cluster.
1213
* <<docs-replication,Reading and writing documents>>: Learn how {es} replicates read and write operations across shards and shard copies.
1314
* <<shard-allocation-relocation-recovery,Shard allocation, relocation, and recovery>>: Learn how {es} allocates and balances shards across nodes.
15+
* <<shard-request-cache,Shard request cache>>: Learn how {es} caches search requests to improve performance.
1416
--
1517
1618
include::nodes-shards.asciidoc[]
19+
include::node-roles.asciidoc[]
1720
include::docs/data-replication.asciidoc[leveloffset=-1]
18-
include::modules/shard-ops.asciidoc[]
21+
include::modules/shard-ops.asciidoc[]
22+
include::shard-request-cache.asciidoc[leveloffset=-1]

docs/reference/modules/discovery/publishing.asciidoc

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,23 @@
1+
[[cluster-state-overview]]
2+
=== Cluster state
3+
4+
The _cluster state_ is an internal data structure which keeps track of a
5+
variety of information needed by every node, including:
6+
7+
* The identity and attributes of the other nodes in the cluster
8+
9+
* Cluster-wide settings
10+
11+
* Index metadata, including the mapping and settings for each index
12+
13+
* The location and status of every shard copy in the cluster
14+
15+
The elected master node ensures that every node in the cluster has a copy of
16+
the same cluster state. The <<cluster-state,cluster state API>> lets you retrieve a
17+
representation of this internal state for debugging or diagnostic purposes.
18+
119
[[cluster-state-publishing]]
2-
=== Publishing the cluster state
20+
==== Publishing the cluster state
321

422
The elected master node is the only node in a cluster that can make changes to
523
the cluster state. The elected master node processes one batch of cluster state
@@ -58,3 +76,16 @@ speed of the storage on each master-eligible node, as well as the reliability
5876
and latency of the network interconnections between all nodes in the cluster.
5977
You must therefore ensure that the storage and networking available to the
6078
nodes in your cluster are good enough to meet your performance goals.
79+
80+
[[dangling-indices]]
81+
==== Dangling indices
82+
83+
When a node joins the cluster, if it finds any shards stored in its local
84+
data directory that do not already exist in the cluster state, it will consider
85+
those shards to belong to a "dangling" index. You can list, import or
86+
delete dangling indices using the <<dangling-indices-api,Dangling indices
87+
API>>.
88+
89+
NOTE: The API cannot offer any guarantees as to whether the imported data
90+
truly represents the latest state of the data when the index was still part
91+
of the cluster.
Lines changed: 7 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[[shard-request-cache]]
1+
[[shard-request-cache-settings]]
22
=== Shard request cache settings
33

44
When a search request is run against an index or against many indices, each
@@ -10,139 +10,16 @@ The shard-level request cache module caches the local results on each shard.
1010
This allows frequently used (and potentially heavy) search requests to return
1111
results almost instantly. The requests cache is a very good fit for the logging
1212
use case, where only the most recent index is being actively updated --
13-
results from older indices will be served directly from the cache.
13+
results from older indices will be served directly from the cache. You can use shard request cache settings to control the size and expiration of the cache.
1414

15-
[IMPORTANT]
16-
===================================
17-
18-
By default, the requests cache will only cache the results of search requests
19-
where `size=0`, so it will not cache `hits`,
20-
but it will cache `hits.total`, <<search-aggregations,aggregations>>, and
21-
<<search-suggesters,suggestions>>.
22-
23-
Most queries that use `now` (see <<date-math>>) cannot be cached.
24-
25-
Scripted queries that use the API calls which are non-deterministic, such as
26-
`Math.random()` or `new Date()` are not cached.
27-
===================================
28-
29-
[discrete]
30-
==== Cache invalidation
31-
32-
The cache is smart -- it keeps the same _near real-time_ promise as uncached
33-
search.
34-
35-
Cached results are invalidated automatically whenever the shard refreshes to
36-
pick up changes to the documents or when you update the mapping. In other
37-
words you will always get the same results from the cache as you would for an
38-
uncached search request.
39-
40-
The longer the refresh interval, the longer that cached entries will remain
41-
valid even if there are changes to the documents. If the cache is full, the
42-
least recently used cache keys will be evicted.
43-
44-
The cache can be expired manually with the <<indices-clearcache,`clear-cache` API>>:
45-
46-
[source,console]
47-
------------------------
48-
POST /my-index-000001,my-index-000002/_cache/clear?request=true
49-
------------------------
50-
// TEST[s/^/PUT my-index-000001\nPUT my-index-000002\n/]
51-
52-
[discrete]
53-
==== Enabling and disabling caching
54-
55-
The cache is enabled by default, but can be disabled when creating a new
56-
index as follows:
57-
58-
[source,console]
59-
-----------------------------
60-
PUT /my-index-000001
61-
{
62-
"settings": {
63-
"index.requests.cache.enable": false
64-
}
65-
}
66-
-----------------------------
67-
68-
It can also be enabled or disabled dynamically on an existing index with the
69-
<<indices-update-settings,`update-settings`>> API:
70-
71-
[source,console]
72-
-----------------------------
73-
PUT /my-index-000001/_settings
74-
{ "index.requests.cache.enable": true }
75-
-----------------------------
76-
// TEST[continued]
77-
78-
79-
[discrete]
80-
==== Enabling and disabling caching per request
81-
82-
The `request_cache` query-string parameter can be used to enable or disable
83-
caching on a *per-request* basis. If set, it overrides the index-level setting:
84-
85-
[source,console]
86-
-----------------------------
87-
GET /my-index-000001/_search?request_cache=true
88-
{
89-
"size": 0,
90-
"aggs": {
91-
"popular_colors": {
92-
"terms": {
93-
"field": "colors"
94-
}
95-
}
96-
}
97-
}
98-
-----------------------------
99-
// TEST[continued]
100-
101-
Requests where `size` is greater than 0 will not be cached even if the request cache is
102-
enabled in the index settings. To cache these requests you will need to use the
103-
query-string parameter detailed here.
104-
105-
[discrete]
106-
==== Cache key
107-
108-
A hash of the whole JSON body is used as the cache key. This means that if the JSON
109-
changes -- for instance if keys are output in a different order -- then the
110-
cache key will not be recognised.
111-
112-
TIP: Most JSON libraries support a _canonical_ mode which ensures that JSON
113-
keys are always emitted in the same order. This canonical mode can be used in
114-
the application to ensure that a request is always serialized in the same way.
15+
To learn more about the shard request cache, see <<shard-request-cache>>.
11516

11617
[discrete]
11718
==== Cache settings
11819

119-
The cache is managed at the node level, and has a default maximum size of `1%`
120-
of the heap. This can be changed in the `config/elasticsearch.yml` file with:
121-
122-
[source,yaml]
123-
--------------------------------
124-
indices.requests.cache.size: 2%
125-
--------------------------------
126-
127-
Also, you can use the +indices.requests.cache.expire+ setting to specify a TTL
128-
for cached results, but there should be no reason to do so. Remember that
129-
stale results are automatically invalidated when the index is refreshed. This
130-
setting is provided for completeness' sake only.
131-
132-
[discrete]
133-
==== Monitoring cache usage
134-
135-
The size of the cache (in bytes) and the number of evictions can be viewed
136-
by index, with the <<indices-stats,`indices-stats`>> API:
137-
138-
[source,console]
139-
------------------------
140-
GET /_stats/request_cache?human
141-
------------------------
20+
indices.requests.cache.size::
21+
(<<static-cluster-setting,Static>>) The maximum size of the cache, as a percentage of the heap. Default: `1%`.
14222

143-
or by node with the <<cluster-nodes-stats,`nodes-stats`>> API:
23+
indices.requests.cache.expire::
24+
(<<static-cluster-setting,Static>>) The TTL for cached results. Stale results are automatically invalidated when the index is refreshed, so you shouldn't need to use this setting.
14425

145-
[source,console]
146-
------------------------
147-
GET /_nodes/stats/indices/request_cache?human
148-
------------------------

0 commit comments

Comments
 (0)