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

**URL:** <https://discuss.elastic.co/t/hi-i-trying-to-search-document-based-on-date-which-is-in-format-mm-dd-yyyy/192829>\
**Category:** Elasticsearch\
**Created:** [July 30, 2019, 6:17am UTC](https://discuss.elastic.co/t/hi-i-trying-to-search-document-based-on-date-which-is-in-format-mm-dd-yyyy/192829 "2019-07-30T06:17:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kartheek91](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kartheek91](https://discuss.elastic.co/u/kartheek91)\
**Post date:** [July 30, 2019, 6:17am UTC](https://discuss.elastic.co/t/hi-i-trying-to-search-document-based-on-date-which-is-in-format-mm-dd-yyyy/192829/1 "2019-07-30T06:17:00Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [July 30, 2019, 6:22am UTC](https://discuss.elastic.co/t/hi-i-trying-to-search-document-based-on-date-which-is-in-format-mm-dd-yyyy/192829/2 "2019-07-30T06:22:19Z")

</div>

Hi @kartheek91,

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

---

<div class="post-metadata">

**Author:** ![kartheek91](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kartheek91](https://discuss.elastic.co/u/kartheek91)\
**Post date:** [July 30, 2019, 6:23am UTC](https://discuss.elastic.co/t/hi-i-trying-to-search-document-based-on-date-which-is-in-format-mm-dd-yyyy/192829/3 "2019-07-30T06:23:02Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![gabriel\_tessier](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gabriel_tessier/32/27911_2.png) [@gabriel\_tessier](https://discuss.elastic.co/u/gabriel_tessier)\
**Post date:** [July 30, 2019, 9:19am UTC](https://discuss.elastic.co/t/hi-i-trying-to-search-document-based-on-date-which-is-in-format-mm-dd-yyyy/192829/4 "2019-07-30T09:19:46Z")

</div>

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"
        }
      }
    ]
  }
}
```

---

<div class="post-metadata">

**Author:** ![kartheek91](https://avatars.discourse-cdn.com/v4/letter/k/cc9497/32.png) [@kartheek91](https://discuss.elastic.co/u/kartheek91)\
**Post date:** [July 30, 2019, 10:39am UTC](https://discuss.elastic.co/t/hi-i-trying-to-search-document-based-on-date-which-is-in-format-mm-dd-yyyy/192829/5 "2019-07-30T10:39:17Z")

</div>

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

---

<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:** [August 27, 2019, 10:39am UTC](https://discuss.elastic.co/t/hi-i-trying-to-search-document-based-on-date-which-is-in-format-mm-dd-yyyy/192829/6 "2019-08-27T10:39:22Z")

</div>

Closed on August 27, 2019, 10:39am UTC

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