Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to turn off caching when testing Elastic Search

I'm stress testing Elastic Search by sending queries but am afraid the responses are being cached. How do I turn off caching when testing Elastic Search?

like image 864
Alex Avatar asked Aug 08 '14 22:08

Alex


People also ask

Does elastic search have cache?

Elasticsearch is a heavy user of various caches, but in this post we'll only be focusing on: Page cache (sometimes called the filesystem cache) Shard-level request cache.

How do I clear elastic search cache?

Clear a specific cacheedit 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.

How do you cache a query?

You can create a Cached Query right from the Explorer. To cache a query, go ahead and save the query first. Fig 1: Press the button to "Save" the query. Then, to cache your most important queries select the “Enable Caching” checkbox and enter a refresh rate.


2 Answers

Before I answer, a disclaimer that I agree with the comments on the question, disabling cache is not the best way to stress test Elasticsearch. Hitting it with simultaneous queries that are representative of your production query set along with active indexing at the same time is going to be a far better way to see how ES responds under load.

However, to answer your question and point out some caveats:

  1. You can clear your cache in between runs:

    The clear cache API allows to clear either all caches or specific cached associated with one ore more indices.

    https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-clearcache.html

  2. You can turn off your filter cache by setting index.cache.filter.type to none - this will prevent filter results from being cached:

    http://elasticsearch-users.115913.n3.nabble.com/Disable-cache-td3825105.html

    http://elasticsearch-users.115913.n3.nabble.com/Disabling-cache-td3201850.html

  3. You can change the settings for the field data cache - however I don't know what will happen if you set this to zero:

    https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-fielddata.html

  4. Overall, though, keep in mind that Elasticsearch makes significant use of the native OS filesystem cache, so much of "caching" is happening outside the control of ES:

    https://blog.codecentric.de/en/2014/05/elasticsearch-indexing-performance-cheatsheet/

like image 53
John Petrone Avatar answered Sep 18 '22 15:09

John Petrone


GET /my_index/_search?request_cache=false

https://www.elastic.co/guide/en/elasticsearch/reference/current/shard-request-cache.html

like image 37
Aditya Agarwal Avatar answered Sep 19 '22 15:09

Aditya Agarwal