We're exploring a move from (self-managed) Elasticsearch 7.17 to Elasticsearch 8.6. Some of the tests on the application fail if we switch. We traced the failure to an inconsistency between the results on the range using the date field. The range query is working properly in 7.17, but it stops getting results for 8.6. The mappings on the field are unchanged. Reproducible example below.
Preparing the data
DELETE /test_index
PUT test_index
{
"mappings": {
"properties": {
"published_date": {
"type" : "date",
"format" : "epoch_second"
},
"name": {
"type": "text"
}
}
}
}
POST test_index/_bulk
{ "index" : { "_id" : "1" } }
{"published_date" : 1923354000, "name": "Nike Shoes"}
{ "index" : { "_id" : "2" } }
{"published_date" : 1923354000, "name": "Adidas Top"}
{ "index" : { "_id" : "3" } }
{"published_date" : 1355360400, "name": "Valentino Bag"}
Not working as expected
POST test_index/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"published_date": {
"gte": 0,
"lte": 2516523214
}
}
}
]
}
}
}
Oops
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
This returns an empty set, though all the results are supposed to match.
However, the same query returns the expected result, meaning all three records, on Elasticsearch 7.17.
The query can be tweaked like this and it will work on 8.6 too
POST test_index/_search
{
"query": {
"bool": {
"must": [
{
"range": {
"published_date": {
"gte": "0",
"lte": "2516523214"
}
}
}
]
}
}
}
The change to the query is very small; it's just quoting the dates in the range, and sending them as strings.
(A side note: in Elasticsearch 7.17, this query works on par with the previous one. I haven't noticed any changes between using strings in this range, or using numbers, for 7.17. But for 8.6, numbers just do not work.)
However, it's not an insignificant change for our app; it requires quite a significant rewrite of code and test cases, and possibly the client apps. I wasn't able to find anything about this change in the listed Java time migration changes.
Is this a change that's described somewhere and was intentional, or is this something that broke between the versions? It's a bit weird that we need to query for the basically numeric values as strings.