Trouble querying for exact date with range query

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

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

And an example doc:

{
    "_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:

{
    "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?

Why not use terms query?

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

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