# rangeQuery for Date with java

**URL:** <https://discuss.elastic.co/t/rangequery-for-date-with-java/210515>\
**Category:** Elasticsearch\
**Created:** [December 4, 2019, 11:00am UTC](https://discuss.elastic.co/t/rangequery-for-date-with-java/210515 "2019-12-04T11:00:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mly\_hmed\_Joti](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mly_hmed_joti/32/58766_2.png) [@mly\_hmed\_Joti](https://discuss.elastic.co/u/mly_hmed_Joti)\
**Post date:** [December 4, 2019, 11:00am UTC](https://discuss.elastic.co/t/rangequery-for-date-with-java/210515/1 "2019-12-04T11:00:23Z")

</div>

i made a query with elasticsearch client in java , and when i try to searching a date they give me this erros

> Failed to execute phase [query], all shards failed; shardFailures {[-AAmwvoOSUmuCZKhW-SZug][car][0]: RemoteTransportException[[-AAmwvo][127.0.0.1:9300][indices:data/read/search[phase/query]]]; nested: ElasticsearchParseException[failed to parse date field [Wed Dec 04 00:00:00 GMT+01:00 2019]

my query code is like :

```auto
    private static final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
    String sourceDate = "2019-12-04T00:00:00.000Z";

        Date myDate = dateFormat.parse(sourceDate);

 if (query == null) {

                        query = QueryBuilders.boolQuery().must(QueryBuilders.rangeQuery("Date Field")

                                .from(myDate)

                                .to(myDate)

                                .includeLower(true)

                                .includeUpper(false));

                    } else {

                        query = query.must(QueryBuilders.rangeQuery("Date Field")

                                .from(myDate)

                                .to(myDate)
                                .includeLower(true)

                                .includeUpper(false));

            }

```

any idea about this problem? Thank you

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 1, 2020, 11:00am UTC](https://discuss.elastic.co/t/rangequery-for-date-with-java/210515/2 "2020-01-01T11:00:42Z")

</div>

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