Elasticsearch doesn't cache query with rounded date

Nodes info API | Elasticsearch Guide [7.12] | Elastic and Nodes stats API | Elasticsearch Guide [7.12] | Elastic would be great as well.

I have updated the gist with that information.

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:

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

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

returns

{
  "_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?

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 :slight_smile:

https://asciinema.org/a/Linjk6aMKX5T3yYUHEX6jfL6w

I fully forgot about asciinema, nice one :slight_smile:

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 :slight_smile:

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 :slight_smile:
Thanks for now!

1 Like

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