# How to disable the query cache

**URL:** https://discuss.elastic.co/t/how-to-disable-the-query-cache/150404
**Category:** Elasticsearch
**Created:** [September 29, 2018, 3:01am UTC](https://discuss.elastic.co/t/how-to-disable-the-query-cache/150404 "2018-09-29T03:01:11Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![bluelullaby](https://avatars.discourse-cdn.com/v4/letter/b/b487fb/32.png) [@bluelullaby](https://discuss.elastic.co/u/bluelullaby)
#### Post date: [September 29, 2018, 3:01am UTC](https://discuss.elastic.co/t/how-to-disable-the-query-cache/150404/1 "2018-09-29T03:01:11Z")

</div>

Recently, I have noticed that searching by Elasticsearch had been performed a bit slowly. So I want to test the performance among the varied query circumstances.

Since Elasticsearch can cache the query result, I need to disable this function to reduce the unrelated affection between the two same query actions.

I set the `false` value to the setting parameters,  
`index.queries.cache.enabled`  
and  
`index.requests.cache.enable`.

But actually it seems not working correctly. The second query action will obviously be faster than the first one during the two continuous query actions, which are in the same query clauses.

My query clause maybe looks like this:

```
{
    "from": 0, 
    "size": 20, 
    "query": {
        "bool": {
            "must": [
                {
                    "match": {
                        "content": "hello world"
                    }
                }, 
                {
                    "term": {
                        "state.raw": {
                            "value": "0"
                        }
                    }
                }, 
                {
                    "term": {
                        "news_type_id.raw": {
                            "value": "10000"
                        }
                    }
                }, 
                {
                    "range": {
                        "channel_id": {
                            "gte": "002000000000000000", 
                            "lt": "003000000000000000"
                        }
                    }
                }
            ]
        }
    }, 
    "sort": [
        {
            "mod_date": {
                "order": "desc", 
            }
        }
    ]
}

```

So my question is:

- How can I disable the query cache, is there any other setting parameter controlling the cache behaviour?

- What is the mechanism of the query or search cache? When I merely change one of the query parameters in the query clause shown above, for example, change the content matching condition from `hello world` to `say hello`, will Elasticsearch retrieve the search result from its cache? Is there any reference to understand the cache mechanism?

Thanks a lot.

---

<div class="post-metadata">

### Author: ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)
#### Post date: [September 29, 2018, 6:38am UTC](https://discuss.elastic.co/t/how-to-disable-the-query-cache/150404/2 "2018-09-29T06:38:58Z")

</div>

The thing is that your OS also caches files that have been read recently. So the next reads are normally faster.

But may be you can ask the community to help about your slowness? Share your queries, responses...  
May be use the profile API to understand which part is slow?

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)
#### Post date: [October 27, 2018, 6:38am UTC](https://discuss.elastic.co/t/how-to-disable-the-query-cache/150404/3 "2018-10-27T06:38:58Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
