# Output date in epoch\_millis format

**URL:** https://discuss.elastic.co/t/output-date-in-epoch-millis-format/105022
**Category:** Logstash
**Created:** [October 24, 2017, 9:06am UTC](https://discuss.elastic.co/t/output-date-in-epoch-millis-format/105022 "2017-10-24T09:06:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![jong99](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jong99](https://discuss.elastic.co/u/jong99)
#### Post date: [October 24, 2017, 9:06am UTC](https://discuss.elastic.co/t/output-date-in-epoch-millis-format/105022/1 "2017-10-24T09:06:27Z")

</div>

I'm trying to use Logstash to replace a custom, overly complex system that I've inherited.

It currently outputs the timestamp of the event into a field called "@ts", but this is stored in _epoch\_millis_ format. I'm trying to get Logstash to output the timestamp in this date format.

Here is the relevant field from the mapping:  
`"@ts": {"format": "epoch_millis", "type": "date"}`

And the raw JSON documents when I retrieve them look like this:  
`"fields": {"@ts": [1508832196000]}`

No matter what I do, I cannot seem to get Logstash to output the date format in _epoch\_millis_ format, and all the documents are discarded when written to that index. If I try to write to a different index with a mapping of _strict\_date\_optional\_time_ then all works perfectly, but the documents are stored in the standard format e.g. "2017-10-24T08:26:09.000Z"

Is there any way to get logstash to output a date in `epoch_millis` format for compatibility?

I've tried [https://github.com/wiibaa/logstash-filter-date\_formatter](https://github.com/wiibaa/logstash-filter-date_formatter) but Joda Time doesn't seem to support Unix timestamps.

Any pointers here? Thanks!

**Edit:**

I've tried using Ruby to set @timestamp to this, but that results in an error:  
`event.set('@timestamp',event.get('@ts').to_i)`  
`Ruby exception occurred: wrong argument type Fixnum (expected LogStash::Timestamp)`

But it looks like I can set @ts to to this  
`event.set('@ts',event.get('@ts').to_i)`

Guessing @timestamp here is a reserved name and can't be overridden.

Still doesn't solve the problem though as something is casting the integer timestamp to a date somewhere.

---

<div class="post-metadata">

### Author: ![jong99](https://avatars.discourse-cdn.com/v4/letter/j/9dc877/32.png) [@jong99](https://discuss.elastic.co/u/jong99)
#### Post date: [October 24, 2017, 10:24am UTC](https://discuss.elastic.co/t/output-date-in-epoch-millis-format/105022/2 "2017-10-24T10:24:27Z")

</div>

Think I'm getting confused here now with @ts and @timestamp, and a combination of issues (notably overwriting the type of @timestamp). I now have @ts stored as an integer using the Ruby code above. Maybe there is a better way to do it?

---

<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: [November 21, 2017, 10:24am UTC](https://discuss.elastic.co/t/output-date-in-epoch-millis-format/105022/3 "2017-11-21T10:24:36Z")

</div>

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