# Index Date values in multiple formats

**URL:** <https://discuss.elastic.co/t/index-date-values-in-multiple-formats/70353>\
**Category:** Elasticsearch\
**Created:** [January 2, 2017, 10:53am UTC](https://discuss.elastic.co/t/index-date-values-in-multiple-formats/70353 "2017-01-02T10:53:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![inadler](https://avatars.discourse-cdn.com/v4/letter/i/ed8c4c/32.png) [@inadler](https://discuss.elastic.co/u/inadler)\
**Post date:** [January 2, 2017, 10:53am UTC](https://discuss.elastic.co/t/index-date-values-in-multiple-formats/70353/1 "2017-01-02T10:53:35Z")

</div>

I wish to index a date value into several fields each in different format.

for example, index "1/1/2011 10:11:12" into two fields:

- time: "HH:mm:ss"
- date: "dd/MM/yyyy HH:mm:ss"

I tried using both multi fields and copy\_to features using the bellow schema but with no luck.  
I get "Invalid format: "1/1/2011 10:11:12" is malformed at "/1/2011 10:11:12""

**copy\_to**  
{  
"mappings": {  
"myIndex": {  
"properties": {  
"time": {  
"type": "date",  
"format": "HH:mm:ss"  
},  
"date": {  
"type": "date",  
"format": "dd/MM/yyyy HH:mm:ss",  
"copy\_to": "time"  
}  
}  
}  
}  
}

**multi field**

{  
"mappings": {  
"myIndex": {  
"properties": {  
"date": {  
"type": "date",  
"format": "dd/MM/yyyy HH:mm:ss",  
"fields": {  
"time": {  
"type": "date",  
"format": "HH:mm:ss"  
}  
}  
}  
}  
}  
}  
}

Is there a way to do it - without using scripts - because i cannot afford having an impact on performance?

---

<div class="post-metadata">

**Author:** ![cbuescher](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cbuescher/32/60402_2.png) [@cbuescher](https://discuss.elastic.co/u/cbuescher)\
**Post date:** [January 2, 2017, 11:09am UTC](https://discuss.elastic.co/t/index-date-values-in-multiple-formats/70353/2 "2017-01-02T11:09:45Z")

</div>

Hi,

it looks like you essentially want to split the input field on whitespace first, then parse each part with a different format. This is usually done e.g. in Logstash before indexing the documents, but I think starting with version 5 of Elasticsearchm this can now also be achieved by using an [Ingest Node](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/ingest.html) and a [Grok Processor](https://www.elastic.co/guide/en/elasticsearch/reference/5.0/grok-processor.html). Other than that I don't see how you can apply formats that only partially match the input field.

---

<div class="post-metadata">

**Author:** ![inadler](https://avatars.discourse-cdn.com/v4/letter/i/ed8c4c/32.png) [@inadler](https://discuss.elastic.co/u/inadler)\
**Post date:** [January 2, 2017, 12:05pm UTC](https://discuss.elastic.co/t/index-date-values-in-multiple-formats/70353/3 "2017-01-02T12:05:06Z")

</div>

Thank you for the quick response.

I am interacting with Elasticsearch using the Java SDK, not logstash.  
I can do it in code, but hoped Elasticsearch will do it for me.

---

<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:** [January 30, 2017, 12:05pm UTC](https://discuss.elastic.co/t/index-date-values-in-multiple-formats/70353/4 "2017-01-30T12:05:07Z")

</div>

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