user12056260
user12056260

Reputation:

Check if elasticsearch query results are coming from cache or not?

I need to compare the 2 different indices(same data with different no of shards) for an elastic-search index, for which I am using some of my slow search queries and hitting on these indices but I am suspecting as one indices is getting the live traffic, hence its possible for my queries results are coming from cache.

Is there is any way to figure out, results are coming from cache or any param which we can specify to not bring results from cache ?

Upvotes: 6

Views: 4799

Answers (1)

A l w a y s S u n n y
A l w a y s S u n n y

Reputation: 38502

By default, the requests cache will only cache the results of search requests where size=0, so it will not cache hits, but it will cache hits.total, aggregations, and suggestions.

The request_cache query-string parameter can be used to enable or disable caching on a per-request basis. If set, it overrides the index-level setting:

GET /my_index/_search?request_cache=true
{
  "size": 0,
  "aggs": {
    "popular_colors": {
      "terms": {
        "field": "colors"
      }
    }
  }
}

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

Upvotes: 4

Related Questions