A, reference

Elasticsearch Learning Series Directory — Update ing

Everything you need to know about ElasticSearch query cache is here

Second,Shard request cache

A shard-level query cache, with each shard having its own cache

2.1 Caching strategy

Not all shard-level queries are cached

2.2 Cache Settings

Three,Node Query Cache

NodeQueryCache is implemented at the Lucene level and is enabled by default. The ES level does some policy control and statistics

3.1 queryCacheUse the sample

3.2 Caching strategy

Not all filter queries will be cached

3.3 Cache Settings

Four,ShardRequestCacheNodeQueryCacheThe comparison of

ShardRequestCache is an ES level implementation with a caching mechanism of LRU. Once accessed, cache will be considered. The main purpose of ShardRequestCache is to cache the aggregated results

NodeQueryCache is the implementation of Lucene level, the caching mechanism is LRU, the access to a certain frequency, will consider the cache, the main purpose is to filter sub-query cache

Other caches

5.1 fielddata

For a field aggregate query of type Text, FieldData is used to get the field value for that field,

(1) FieldData takes up a lot of memory, and the default is to turn it off. (2) Text type aggregated queries are generally not meaningful, so use with caution

5.2 pagecache

During the query, Lucene files are cached by the operating system’s PageCache,

(1) PageCache uses an LRU like policy cache file (2) PageCache is completely controlled by the operating system

6. Monitor the cache

Cache monitoring metrics are usually concerned with :(1) the size of the cache space; (2) Cache hit ratio is divided into node and index levels for analysis

6.1 Node level monitoring

(1) requestCache

GET /_cat/nodes by hitCount/(hitCount + missCount) v&h=name,queryCacheMemory,fielddataMemory,requestCacheMemory,requestCacheHitCount,requestCacheMissCount name QueryCachemory fieldDatamemory requestCachemory requestCacheHitCount requestCachemissCount ES-0001 2.9GB 16.8MB 304.5MB 1138314 1084754 ES-0002 2.2 GB 5.2MB 242.6MB 789616 985675 ES-0003 757.6MB 250KB 264MB 597872 641255

(2) queryCache

GET _nodes/stats/indices/query_cache,request_cache,fielddata? Pretty&human "indices" : {"query_cache" : {"memory_size" : "2.8MB ", "memory_size_in_bytes" : 2969952, "total_count" : 1572593, "hit_count" : 217873, "miss_count" : 1354720, "cache_size" : 891, "cache_count" : 5066, "evictions" : 4175}, "fielddata" : {"memory_size" : "264.8KB ", "memory_size_in_bytes" : 271168," EVICtions ": 0}, "request_cache" : {"memory_size" : "8.2MB ", "memory_size_in_bytes" : 8603352, "evictions" : 0, "hit_count" : 107345, "miss_count" : 26116 } }

6.2 Index level monitoring

GET kibana_sample_data_logs/_stats/query_cache,fielddata,request_cache? pretty&human "total" : { "query_cache" : { "memory_size" : "0b", "memory_size_in_bytes" : 0, "total_count" : 0, "hit_count" : 0, "miss_count" : 0, "cache_size" : 0, "cache_count" : 0, "evictions" : 0 }, "fielddata" : {"memory_size" : "512.3KB ", "memory_size_in_bytes" : 524696, "evictions" : 0}, "request_cache" : {"memory_size" : "memory_size" : "64.2KB ", "memory_size_in_bytes" : 65808, "evictions" : 0, "hit_count" : 0, "miss_count" : 16}}

7. Clear the cache manually

It is not recommended to manually clear the cache in a production environment,

(1) Because manual cleanup will have a great impact on query performance,

(2) Generally manual cleaning is only used for testing and verification

7.1 Clear the cache for the specified index or for all indexes

POST _cache/clear

POST kibana_sample_data_logs/_cache/clear

7.2 Clears the cache of the specified type

POST _cache/clear? query=true POST _cache/clear? request=true POST _cache/clear? fielddata=true POST kibana_sample_data_logs/_cache/clear? query=true POST kibana_sample_data_logs/_cache/clear? request=true POST kibana_sample_data_logs/_cache/clear? fielddata=true

7.3 Clear the cache of some fields

POST kibana_sample_data_logs/_cache/clear? fields=clientip,geo