Date format interchangeable


#1

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.


(David Pilato) #2

Yes you can with elasticsearch.


#3

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


(David Pilato) #4

Could you provide a full recreation script as described in About the Elasticsearch category. 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.


#5

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.


(David Pilato) #6

Try this:

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

#7

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"


(system) closed #8

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