Store Date Format in elasticsearch

Jimmy Lin picture Jimmy Lin · Jul 24, 2013 · Viewed 50.9k times · Source

I met a problem when I want to add one datetime string into Elasticsearch.

The document is below:

{"LastUpdate" : "2013/07/24 00:00:00"}

This document raised an error which is "NumberFormatException" [For input string: \"20130724 00:00:00\"]

I know that I can use the Date Format in Elasticsearch, but I don't know how to use even I read the document on the website.

{"LastUpdate": {
    "properties": {
        "type": "date", 
        "format": "yyyy-MM-dd"}
    }
}

and

{"LastUpdate": {
    "type": "date", 
    "format": "yyyy-MM-dd"
    }
}

are wrong.

How can I transfer the datetime string into date format in Elasticsearch?

How can I store the datetime string directly into Elasticsearch?

Answer

ramseykhalaf picture ramseykhalaf · Jul 24, 2013

You are nearly there. Set your mapping like this:

{"LastUpdate": {
    "type" : "date",
    "format" : "yyyy/MM/dd HH:mm:ss"}
}

Read the docs on the date mapping and its options and the date format parameter (one of the options to the date mapping).

Good luck!