-
Notifications
You must be signed in to change notification settings - Fork 25.8k
Match query on date property with format 'uuuu' (year) acts as a range query for years below 1971 #90187
Copy link
Copy link
Closed
Labels
:Core/Infra/CoreCore issues without another labelCore issues without another label:Search/SearchSearch-related issues that do not fall into other categoriesSearch-related issues that do not fall into other categories>bugTeam:Core/InfraMeta label for core/infra teamMeta label for core/infra teamTeam:SearchMeta label for search teamMeta label for search team
Description
Elasticsearch Version
8.4.2
Installed Plugins
No response
Java Version
bundled
OS Version
Linux yrodiere.redhat 5.19.8-200.fc36.x86_64 #1 SMP PREEMPT_DYNAMIC Thu Sep 8 19:02:21 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
Problem Description
Since Elasticsearch 8.4.2, running a match query on a field of type date with format uuuu will give strange results for years below 1971, similar to running a range query with the range [<your year>, 1970].
Yes, that's very weird.
This bug was not present in Elasticsearch 8.4.1.
Steps to Reproduce
# Just to make it easier to re-run the test
curl -XDELETE localhost:9200/mytest/\?pretty 1>&2 2>/dev/null || true
# Property of type `date` with format `uuuu`
curl -XPUT -H "Content-Type: application/json" localhost:9200/mytest/\?pretty -d'{"mappings":{"properties":{"myyear":{"type":"date","format":"uuuu"}}}}'
# Index year 1971
curl -XPUT -H "Content-Type: application/json" localhost:9200/mytest/_doc/1\?pretty\&refresh=true -d'{"myyear":"1971"}'
# Index two different years below 1971
curl -XPUT -H "Content-Type: application/json" localhost:9200/mytest/_doc/2\?pretty\&refresh=true -d'{"myyear":"1970"}'
curl -XPUT -H "Content-Type: application/json" localhost:9200/mytest/_doc/3\?pretty\&refresh=true -d'{"myyear":"1969"}'
curl -XPUT -H "Content-Type: application/json" localhost:9200/mytest/_doc/4\?pretty\&refresh=true -d'{"myyear":"1500"}'
curl -XPUT -H "Content-Type: application/json" localhost:9200/mytest/_doc/6\?pretty\&refresh=true -d'{"myyear":"0050"}'
curl -XPUT -H "Content-Type: application/json" localhost:9200/mytest/_doc/7\?pretty\&refresh=true -d'{"myyear":"-42"}'
# Search for year 1970: only 1970 matches
curl -XPOST -H "Content-Type: application/json" localhost:9200/mytest/_search\?pretty -d'{"query":{"match":{"myyear":{"query":"1970"}}}}'
# Search for year 1969: both 1969 and 1970 match (???) but not 1971
curl -XPOST -H "Content-Type: application/json" localhost:9200/mytest/_search\?pretty -d'{"query":{"match":{"myyear":{"query":"1970"}}}}'
# Search for year 1500: 1500, 1969 and 1970 match (???) but not 1971
curl -XPOST -H "Content-Type: application/json" localhost:9200/mytest/_search\?pretty -d'{"query":{"match":{"myyear":{"query":"1500"}}}}'
# Search for year 0001: 0050, 1500, 1969 and 1970 match (???) but not 1971
curl -XPOST -H "Content-Type: application/json" localhost:9200/mytest/_search\?pretty -d'{"query":{"match":{"myyear":{"query":"0001"}}}}'Logs (if relevant)
(Incorrect) result of the last two requests in the script above with Elasticsearch 8.4.2:
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "mytest",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"myyear" : "1970"
}
},
{
"_index" : "mytest",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"myyear" : "1969"
}
},
{
"_index" : "mytest",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"myyear" : "1500"
}
}
]
}
}
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 4,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "mytest",
"_id" : "2",
"_score" : 1.0,
"_source" : {
"myyear" : "1970"
}
},
{
"_index" : "mytest",
"_id" : "3",
"_score" : 1.0,
"_source" : {
"myyear" : "1969"
}
},
{
"_index" : "mytest",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"myyear" : "1500"
}
},
{
"_index" : "mytest",
"_id" : "6",
"_score" : 1.0,
"_source" : {
"myyear" : "0050"
}
}
]
}
}(Correct) result of the last two requests in the script above with Elasticsearch 8.4.1:
{
"took" : 3,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "mytest",
"_id" : "4",
"_score" : 1.0,
"_source" : {
"myyear" : "1500"
}
}
]
}
}
{
"took" : 2,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 0,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
:Core/Infra/CoreCore issues without another labelCore issues without another label:Search/SearchSearch-related issues that do not fall into other categoriesSearch-related issues that do not fall into other categories>bugTeam:Core/InfraMeta label for core/infra teamMeta label for core/infra teamTeam:SearchMeta label for search teamMeta label for search team
Type
Fields
Give feedbackNo fields configured for issues without a type.