HI I trying to search document based on date which is in format 'mm/dd/yyyy'?

So my query is

{
"_source": "dob",
"query": {
"bool": {
"must": [
{
"term": {
"dob": "01/01/1965"
}
}
]
}
}
}
I'm getting documents having 11/01/1965, 12/01/1965, 01/01/1965 etc So I need to get only documents that are matched with this date 01/01/1965

Thanks
Kartheek

Hi @kartheek91,

You may have a problem with your mapping what index/doc/_mapping return for the filed "dob"? is it date field?

I have see that also the mapping type is date and format is mm/dd/yyyy

Hi,

I tried with this and it work (elastic version 6.8), if you provide more information or a simple use case it may help to figure out the problem.
If you use a different version >7 you need to make some small changes, check the documentation.

# delete any previous index to start from clean version
DELETE my_index

# set a mapping as guessed from your question
PUT my_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "dob": {
          "type":   "date",
          "format": "MM/dd/yyyy"
        }
      }
    }
  }
}

# put several document as in your first question.
POST _bulk
{ "index" : { "_index" : "my_index", "_type" : "_doc", "_id" : "1" } }
{ "dob" : "01/01/1965" }
{ "index" : { "_index" : "my_index", "_type" : "_doc", "_id" : "2" } }
{ "dob" : "01/11/1965" }
{ "index" : { "_index" : "my_index", "_type" : "_doc", "_id" : "3" } }
{ "dob" : "12/01/1965" }

# make a term search
GET my_index/_doc/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "term": {
            "dob": "01/01/1965"
          }
        }
      ]
    }
  }
}

it return only one document:

{
  "took" : 5,
  "timed_out" : false,
  "_shards" : {
    "total" : 1,
    "successful" : 1,
    "skipped" : 0,
    "failed" : 0
  },
  "hits" : {
    "total" : 1,
    "max_score" : 1.0,
    "hits" : [
      {
        "_index" : "my_index",
        "_type" : "_doc",
        "_id" : "1",
        "_score" : 1.0,
        "_source" : {
          "dob" : "01/01/1965"
        }
      }
    ]
  }
}

Let me check and I will get back to you and I'm using elastic version 6.7