# Date format interchangeable

**URL:** <https://discuss.elastic.co/t/date-format-interchangeable/127935>\
**Category:** Elasticsearch\
**Created:** [April 13, 2018, 9:02am UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935 "2018-04-13T09:02:02Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Varan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varan/32/32120_2.png) [@Varan](https://discuss.elastic.co/u/Varan)\
**Post date:** [April 13, 2018, 9:02am UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935/1 "2018-04-13T09:02:02Z")

</div>

Hi,

I'm using ES 6.2.2

I have multiple date format, so I have precised them in the format like this:  
`"format": "date|| basic_date",`

So `20060606` can be indexed via "`basic_date`" and `2005-05-05` can be indexed via "`date`".

My question is, could I found those date if I use the other format?  
Couldn't I found something with `20050505` and `2006-06-06` ?  
Is something like this possible in ES? Or must I use Logstash?

Thanks.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 13, 2018, 9:15am UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935/2 "2018-04-13T09:15:21Z")

</div>

Yes you can with elasticsearch.

---

<div class="post-metadata">

**Author:** ![Varan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varan/32/32120_2.png) [@Varan](https://discuss.elastic.co/u/Varan)\
**Post date:** [April 13, 2018, 9:18am UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935/3 "2018-04-13T09:18:54Z")

</div>

Hi dadoonet  
Do you mean with some kind of analyzer?  
Because at my point, a query on`2006-06-06` does not find my `20060606`.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 13, 2018, 9:30am UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935/4 "2018-04-13T09:30:53Z")

</div>

Could you provide a full recreation script as described in [About the Elasticsearch category](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will help to better understand what you are doing. Please, try to keep the example as simple as possible.

A full reproduction script will help readers to understand, reproduce and if needed fix your problem. It will also most likely help to get a faster answer.

---

<div class="post-metadata">

**Author:** ![Varan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varan/32/32120_2.png) [@Varan](https://discuss.elastic.co/u/Varan)\
**Post date:** [April 13, 2018, 10:00am UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935/5 "2018-04-13T10:00:25Z")

</div>

Here I go @dadoonet :

```
PUT date_index
{
  "mappings": {
    "_doc": {
      "properties": {
        "birth": {
          "type": "date",
          "format": "yyyy-MM-dd || dd/MM/yyyy || dd-MM-yyyy"
        }
      }
    }
  }
}

```

#So I enabled here three format for my dates.

```
POST date_index/_doc/
{"birth":"01/02/2005"}

```

#Here I index a date according to the second format.

`GET date_index/_search?q="01/02/2005"`

#This one work since it's litterally what I indexed by the second format.

`GET date_index/_search?q="01-02-2005"`

#This one work too, according to the third format.

`GET date_index/_search?q="2005-02-01"`

#This one doesn't. Even though it follow the first format. Why?

**Also thanks for taking time to help me.**

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 13, 2018, 11:54am UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935/6 "2018-04-13T11:54:57Z")

</div>

Try this:

```auto
GET date_index/_search?q=birth:01/02/2005
GET date_index/_search?q=birth:01-02-2005
GET date_index/_search?q=birth:2005-02-01

```

---

<div class="post-metadata">

**Author:** ![Varan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/varan/32/32120_2.png) [@Varan](https://discuss.elastic.co/u/Varan)\
**Post date:** [April 13, 2018, 1:16pm UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935/7 "2018-04-13T13:16:37Z")

</div>

My bad, I put a typo mistake in my set mapping.  
Everything's fine now, but:

`GET date_index/_search?q=birth:01/02/2005`  
This doesn't work, since / is a logical character.

But those work so i'll be fine.  
`GET date_index/_search?q=birth:"01/02/2005"`  
`GET date_index/_search?q="01/02/2005"`

---

<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:** [May 11, 2018, 1:16pm UTC](https://discuss.elastic.co/t/date-format-interchangeable/127935/8 "2018-05-11T13:16:53Z")

</div>

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