Indexing date field in elasticsearch

i have applied following mapping in my index
PUT prince2/
{
"mappings": {
"properties": {
"account_id": {
"type": "long"
},
"created_at": {
"type": "date"
},
"email": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
}
}
}
}

i am trying to index following document with created at as date field.

POST prince2/_doc
{
"account_id": "244108",
"email": "user794815@green.com",
"created_at": "2011-03-12 00:00:26.371 +0000 UTC",
}

i am getting the following error

{
"error": {
"root_cause": [
{
"type": "mapper_parsing_exception",
"reason": "failed to parse field [created_at] of type [date] in document with id 'pDw2W24Bxhx0nqPtLV3U'. Preview of field's value: '2011-03-12 00:00:26.371 +0000 UTC'"
}
],
"type": "mapper_parsing_exception",
"reason": "failed to parse field [created_at] of type [date] in document with id 'pDw2W24Bxhx0nqPtLV3U'. Preview of field's value: '2011-03-12 00:00:26.371 +0000 UTC'",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "failed to parse date field [2011-03-12 00:00:26.371 +0000 UTC] with format [strict_date_optional_time||epoch_millis]",
"caused_by": {
"type": "date_time_parse_exception",
"reason": "Failed to parse with all enclosed parsers"
}
}
},
"status": 400
}

am i doing something wrong here...

Hi @RITZ_VERMA,

I think the error messae is explicit enough

You can check the documentation and choose the correct format.

Thanks @gabriel_tessier ,is there a way to index the same time format.

Yes as written in the documentation:

Date formats can be customised, but if no format is specified then it uses the default:

"strict_date_optional_time||epoch_millis"

And a couple of line under you have an example on how to.

Here the direct link to the section:

You can try one of the build in format and check if it match yours.

Thanks @gabriel_tessier i have gone through the links above but did not find the format i am trying to index.

Hi,

May try something like this as your format is not in the list of build-in list.

PUT my_index
{
"mappings": {
"properties": {
"date": {
"type": "date",
"format": "yyyy-MM-dd HH:mm:ss.SSS Z"
}
}
}
}

You can also check the template to define your date format if you always use this format for all your dates.

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