# Trouble querying for exact date with range query

**URL:** <https://discuss.elastic.co/t/trouble-querying-for-exact-date-with-range-query/258750>\
**Category:** Elasticsearch\
**Created:** [December 15, 2020, 7:13pm UTC](https://discuss.elastic.co/t/trouble-querying-for-exact-date-with-range-query/258750 "2020-12-15T19:13:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matthew\_Ehinger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matthew_ehinger/32/80928_2.png) [@Matthew\_Ehinger](https://discuss.elastic.co/u/Matthew_Ehinger)\
**Post date:** [December 15, 2020, 7:13pm UTC](https://discuss.elastic.co/t/trouble-querying-for-exact-date-with-range-query/258750/1 "2020-12-15T19:13:25Z")

</div>

Hello, I have the following mapping definition in my `events` index:

```auto
{
  "events": {
    "mappings": {
      "properties": {
        "data": {
          "properties": {
            "reportDate": {
              "type": "date",
              "format": "M/d/YYYY"
            }
         }
       }
    }
  }
}

```

And an example doc:

```auto
{
    "_index": "events",
    "_type": "_doc",
    "_id": "12345",
    "_version": 1,
    "_seq_no": 90,
    "_primary_term": 1,
    "found": true,
    "_source": {
        "data": {
            "reportDate": "12/4/2018",
        }
    }
}

```

My goal is query for docs with an exact `data.reportDate` of `12/4/2018`, but when I run this query:

```auto
{
    "query": {
        "range": {
            "data.reportDate": {
                "lte": "12/4/2018",
                "gte": "12/4/2018",
                "format": "M/d/YYYY"
            }
        }
    }
}

```

I instead get all of the docs that have a `data.reportDate` that is in the year 2018, not just 12/4/2018. I've tried setting `relation` to `CONTAINS` and `WITHIN` with no luck. Any ideas?

---

<div class="post-metadata">

**Author:** ![AClerk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aclerk/32/55297_2.png) [@AClerk](https://discuss.elastic.co/u/AClerk)\
**Post date:** [December 16, 2020, 4:05am UTC](https://discuss.elastic.co/t/trouble-querying-for-exact-date-with-range-query/258750/2 "2020-12-16T04:05:41Z")

</div>

Why not use terms query?

> **[Terms query | Elasticsearch Reference \[7.10\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html)**

```auto
GET /_search
{
  "query": {
    "terms": {
      "reportDate": ["12/4/2018"],
      "boost": 1.0
    }
  }
}

```

---

<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 13, 2021, 4:05am UTC](https://discuss.elastic.co/t/trouble-querying-for-exact-date-with-range-query/258750/3 "2021-01-13T04:05:41Z")

</div>

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