# Indexing date field in elasticsearch

**URL:** <https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383>\
**Category:** Elasticsearch\
**Created:** [November 11, 2019, 3:54pm UTC](https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383 "2019-11-11T15:54:03Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RITZ\_VERMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritz_verma/32/46899_2.png) [@RITZ\_VERMA](https://discuss.elastic.co/u/RITZ_VERMA)\
**Post date:** [November 11, 2019, 3:54pm UTC](https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383/1 "2019-11-11T15:54:03Z")

</div>

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](mailto: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...

---

<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:** [November 12, 2019, 1:55am UTC](https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383/2 "2019-11-12T01:55:06Z")

</div>

Hi @RITZ_VERMA,

I think the error messae is explicit enough

> [@RITZ\_VERMA](#):
>
> "reason": "failed to parse date field [2011-03-12 00:00:26.371 +0000 UTC] with format [strict\_date\_optional\_time||epoch\_millis]",

You can check the documentation and choose the correct format.

> **[Date datatype | Elasticsearch Guide \[7.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/date.html)**

---

<div class="post-metadata">

**Author:** ![RITZ\_VERMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritz_verma/32/46899_2.png) [@RITZ\_VERMA](https://discuss.elastic.co/u/RITZ_VERMA)\
**Post date:** [November 12, 2019, 6:23am UTC](https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383/3 "2019-11-12T06:23:29Z")

</div>

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

---

<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:** [November 13, 2019, 4:23am UTC](https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383/4 "2019-11-13T04:23:53Z")

</div>

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:

> **[Date datatype | Elasticsearch Guide \[7.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/date.html#multiple-date-formats)**

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

> **[format | Elasticsearch Guide \[7.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/mapping-date-format.html#built-in-date-formats)**

---

<div class="post-metadata">

**Author:** ![RITZ\_VERMA](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ritz_verma/32/46899_2.png) [@RITZ\_VERMA](https://discuss.elastic.co/u/RITZ_VERMA)\
**Post date:** [November 13, 2019, 4:13pm UTC](https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383/5 "2019-11-13T16:13:16Z")

</div>

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

---

<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:** [November 14, 2019, 12:15am UTC](https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383/6 "2019-11-14T00:15:11Z")

</div>

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.

> **[Put index template API | Elasticsearch Guide \[7.4\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.4/indices-templates.html)**

---

<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:** [December 12, 2019, 12:15am UTC](https://discuss.elastic.co/t/indexing-date-field-in-elasticsearch/207383/7 "2019-12-12T00:15:17Z")

</div>

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