# OpenSearch 1.3 Java HighLevelRestClient Range query not working for date field

**URL:** https://forum.opensearch.org/t/opensearch-1-3-java-highlevelrestclient-range-query-not-working-for-date-field/15687
**Category:** OpenSearch Client Libraries
**Tags:** opensearch-java
**Created:** [August 28, 2023, 6:08pm UTC](https://forum.opensearch.org/t/opensearch-1-3-java-highlevelrestclient-range-query-not-working-for-date-field/15687 "2023-08-28T18:08:07Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![shantanusinghal](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.opensearch.org/shantanusinghal/32/6053_2.png) [@shantanusinghal](https://forum.opensearch.org/u/shantanusinghal)
#### Post date: [August 28, 2023, 6:08pm UTC](https://forum.opensearch.org/t/opensearch-1-3-java-highlevelrestclient-range-query-not-working-for-date-field/15687/1 "2023-08-28T18:08:07Z")

</div>

**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

```auto
GET suggestions/_search
{
  "query": {
    "bool": {
      "filter": [
        {
          "range": {
            "data.constraints.startTime": {
              "lte": "now"
            }
          }
        },
        {
          "range": {
            "data.constraints.endTime": {
              "gte": "now"
            }
          }
        }
      ]
    }
  }
}

```

Java client query

```auto
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.

```auto
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** :

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex019/uploads/mauve_hedgehog/original/2X/3/33547ea01a5b12dcca2958411d3edd97ae2ea8c1.png) [@system](https://forum.opensearch.org/u/system)
#### Post date: [October 27, 2023, 6:08pm UTC](https://forum.opensearch.org/t/opensearch-1-3-java-highlevelrestclient-range-query-not-working-for-date-field/15687/2 "2023-10-27T18:08:15Z")

</div>

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