Versions (relevant - OpenSearch/Dashboard/Server OS/Browser):
org.opensearch.client:opensearch-rest-high-level-client/1.2.0
Describe the issue:
The following Range query on a date fields (startTime and endTime) works from the Dashboard but fails to take effect when added to the SearchRequest that is sent to the Java RestHighLevelClient.
Dashboard query
GET suggestions/_search
{
"query": {
"bool": {
"filter": [
{
"range": {
"data.constraints.startTime": {
"lte": "now"
}
}
},
{
"range": {
"data.constraints.endTime": {
"gte": "now"
}
}
}
]
}
}
}
Java client query
BoolQueryBuilder query = QueryBuilders.boolQuery();
query.must(QueryBuilders.rangeQuery("data.constraints.startTime").lte("now"));
query.must(QueryBuilders.rangeQuery("data.constraints.endTime").gte("now"));
SearchRequest searchRequest = new SearchRequest("suggestions");
searchRequest.source(new SearchSourceBuilder().query(query));
SearchResponse searchResponse = client.search(searchRequest, RequestOptions.DEFAULT);
Configuration:
I’ve tried configuring the query with date strings (like “2023-08-01”) and milliseconds values, but neither of those work from the Java client either.
I’ve also verified that the index mapping to ensure that the Date field type is correctly defined for startTime and endTime.
GET suggestions
{
"suggestions" : {
"aliases" : { },
"mappings" : {
"properties" : {
"data" : {
"properties" : {
"constraints" : {
"properties" : {
"_type" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"endTime" : {
"type" : "date"
},
"startTime" : {
"type" : "date"
}
}
}
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1679337279667",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "kZKHFFanR_K4iYE0JySbLA",
"version" : {
"created" : "135248027"
},
"provided_name" : "suggestions"
}
}
}
}
Relevant Logs or Screenshots: