[BUG] Radial KNN search with date range - inconsistent results
Describe the bug
Inconsistent filtering on a query with the following characteristics:
- KNN query
- Using min_score (radial search)
- Has a date range filter
When the query has these characteristics, the date range filter does not seem to work properly.
My field is defined like this:
"ExpirationDate": {
"type": "date"
},I have a record where ExpirationDate = 2028-10-20 which should be returned
# returns no results
"range": {
"ExpirationDate": {
"gt": "2026-09-24T20:23:03.1897021"
}# returns expected record (changed month to 10)
"range": {
"ExpirationDate": {
"gt": "2026-10-24T20:23:03.1897021"
}Removing the range filter completely also returns the expected record, with the ExpirationDate of 2028-10-20.
Months greater than or equal to 10 seem to filter correctly (returns valid result), less than or equal to 9 does not filter correctly (returns no result when expecting one)
It almost seems as if the range is doing a lexographical comparison. Specifying the "format" of the date does not change the outcome
Related component
Search
To Reproduce
"query": { "knn": { "my_vector": { "vector": [ ....vector_here ], "filter": { "bool": { "filter": [ { "range": { "ExpirationDate": { "gt": "2026-09-24T20:23:03.1941879", "format": "strict_date_optional_time" } } } ] } }, "min_score": 0.7 } } },
Expected behavior
Filtering on a date column works on a KNN radial search
Additional Details
Plugins None
Host/Environment (please complete the following information):
- AWS OpenSearch
- Version Info: OpenSearch 3.7 (latest)
- Service software versionInfo: OpenSearch_3_7_R20260728-P1
Additional context
I originally noticed this on a hybrid query, but experienced the same behavior when doing a straight KNN query as shown above.
This issue does not exist when running a KNN query using K(). I was only able to reproduce it when doing min_score.
The threshold of the min_score is not related. I get the same behavior at min_score=0.005 as min_score = 0.7
Source: opensearch-project/OpenSearch