# Mapping and Scripting

**URL:** <https://discuss.elastic.co/t/mapping-and-scripting/192315>\
**Category:** Kibana\
**Created:** [July 25, 2019, 8:06pm UTC](https://discuss.elastic.co/t/mapping-and-scripting/192315 "2019-07-25T20:06:11Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![cjcenizal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cjcenizal/32/11216_2.png) [@cjcenizal](https://discuss.elastic.co/u/cjcenizal)\
**Post date:** [July 26, 2019, 11:09pm UTC](https://discuss.elastic.co/t/mapping-and-scripting/192315/2 "2019-07-26T23:09:51Z")

</div>

Hi there, to do this you'll need to parse your Kafka timestamp into epoch time in milliseconds. I'm not sure of the format of your timestamp so you'll need to refer to the SimpleDateFormat docs for the correct pattern to use, but here's an example of how you'd like that:

```auto
def kafka = new SimpleDateFormat('YYYY-MM-DD:HH:mm:ss.SSS').parse(doc['kafka_timestamp'].value).getTime();
def spark_process_time = doc['spark_process_time'].value;
return spark_process_time - kafka_timestamp; // Difference between the two in milliseconds

```

You don't need to convert the spark process time because that will already be in epoch time in milliseconds ([date field docs](https://www.elastic.co/guide/en/elasticsearch/reference/6.2/modules-scripting-expression.html#_date_field_api)).

See this thread for more info and a link to the SimpleDateFormat docs: [Converting a string date to a Date field using scripted fields in kibana](https://discuss.elastic.co/t/converting-a-string-date-to-a-date-field-using-scripted-fields-in-kibana/108952)

---

_[View the full topic](https://discuss.elastic.co/t/mapping-and-scripting/192315)._
