# Elasticsearch doesn't cache query with rounded date

**URL:** <https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706>\
**Category:** Elasticsearch\
**Created:** [April 9, 2021, 12:59pm UTC](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706 "2021-04-09T12:59:35Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 15, 2021, 9:49am UTC](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706/21 "2021-04-15T09:49:37Z")

</div>

[Nodes info API | Elasticsearch Guide [7.12] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.12/cluster-nodes-info.html) and [Nodes stats API | Elasticsearch Guide [7.12] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.12/cluster-nodes-stats.html) would be great as well.

---

<div class="post-metadata">

**Author:** ![tlinhart](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tlinhart](https://discuss.elastic.co/u/tlinhart)\
**Post date:** [April 15, 2021, 9:57am UTC](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706/22 "2021-04-15T09:57:42Z")

</div>

I have updated the gist with that information.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 15, 2021, 10:48am UTC](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706/23 "2021-04-15T10:48:50Z")

</div>

Thanks, all of that looks fine. I fail to see the difference between the two setups of us. I just took your docker setup and ran the following snippets:

```auto
DELETE test

PUT test 
{
  "settings": {
    "number_of_shards": 1,
    "number_of_replicas": 0
  }
}

PUT test/_doc/1
{
  "address" : {
    "country" : "T1",
    "city" : "T2"
  },
  "last_seen" : "2021-04-15T12:34:56.789Z",
  "area" : 10.0
}

PUT test/_doc/2
{
  "address" : {
    "country" : "T1",
    "city" : "T2"
  },
  "last_seen" : "2021-04-15T12:34:56.789Z",
  "area" : 10.0
}

PUT test/_doc/3
{
  "address" : {
    "country" : "T1",
    "city" : "T2"
  },
  "last_seen" : "2021-04-15T12:34:56.789Z",
  "area" : 10.0
}

# verify fields are mapped correctly
GET test/_mapping

# run this four times
GET test/_search?request_cache=true
{
  "query": {
    "constant_score": {
      "filter": {
        "bool": {
          "filter": [
            {
              "term": {
                "address.country.keyword": "T1"
              }
            },
            {
              "term": {
                "address.city.keyword": "T2"
              }
            },
            {
              "range": {
                "last_seen": {
                  "gte": "now-3d/d"
                }
              }
            }
          ]
        }
      }
    }
  },
  "aggs": {
    "area": {
      "stats": {
        "field": "area"
      }
    }
  },
  "size": 0
}

```

Then getting the stats

```auto
GET test/_stats?filter_path=_all.primaries.request_cache,_all.primaries.query_cache

```

returns

```auto
{
  "_all" : {
    "primaries" : {
      "query_cache" : {
        "memory_size_in_bytes" : 0,
        "total_count" : 0,
        "hit_count" : 0,
        "miss_count" : 0,
        "cache_size" : 0,
        "cache_count" : 0,
        "evictions" : 0
      },
      "request_cache" : {
        "memory_size_in_bytes" : 804,
        "evictions" : 0,
        "hit_count" : 3,
        "miss_count" : 1
      }
    }
  }
}

```

So, we can rule out the docker setup as well it seems. Have you tried starting a new node/fresh docker container without data and tried the above steps?

---

<div class="post-metadata">

**Author:** ![tlinhart](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tlinhart](https://discuss.elastic.co/u/tlinhart)\
**Post date:** [April 15, 2021, 12:17pm UTC](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706/24 "2021-04-15T12:17:19Z")

</div>

Yeah, the only difference (I hope!) is that I use `curl` for API calls. I've recorded the session so you can see for yourself 🙂

[https://asciinema.org/a/Linjk6aMKX5T3yYUHEX6jfL6w](https://asciinema.org/a/Linjk6aMKX5T3yYUHEX6jfL6w)

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [April 15, 2021, 3:27pm UTC](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706/25 "2021-04-15T15:27:22Z")

</div>

I fully forgot about asciinema, nice one 🙂

So, the shell script misses repeated calls of your same search request to see if the cache gets populated, the first one was a miss as expected and the cache is filled (the size is greater than zero), the interesting part are the next requests you will issue..

Looking forward to more cinema 🙂

---

<div class="post-metadata">

**Author:** ![tlinhart](https://avatars.discourse-cdn.com/v4/letter/t/34f0e0/32.png) [@tlinhart](https://discuss.elastic.co/u/tlinhart)\
**Post date:** [April 15, 2021, 3:39pm UTC](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706/26 "2021-04-15T15:39:48Z")

</div>

Well, now I feel really dumb... Of course it does work now and uses the cache. But I swear I tested it manually (running just the search part) couple of times and the stats didn't move at all.  
I'll try to repeat the same on my own data and get back, maybe with some more cinema 🙂  
Thanks for now!

---

<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:** [May 13, 2021, 3:39pm UTC](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706/27 "2021-05-13T15:39:53Z")

</div>

Closed on May 13, 2021, 3:39pm UTC

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

[Previous page](https://discuss.elastic.co/t/elasticsearch-doesnt-cache-query-with-rounded-date/269706.md?page=1)
