# Trying to Compare two timestamps to calculate ingestion speed

**URL:** <https://discuss.elastic.co/t/trying-to-compare-two-timestamps-to-calculate-ingestion-speed/286823>\
**Category:** Kibana\
**Tags:** painless, ingest-pipeline\
**Created:** [October 15, 2021, 11:59am UTC](https://discuss.elastic.co/t/trying-to-compare-two-timestamps-to-calculate-ingestion-speed/286823 "2021-10-15T11:59:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![jamesm1](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jamesm1](https://discuss.elastic.co/u/jamesm1)\
**Post date:** [October 15, 2021, 11:59am UTC](https://discuss.elastic.co/t/trying-to-compare-two-timestamps-to-calculate-ingestion-speed/286823/1 "2021-10-15T11:59:29Z")

</div>

Hello!  
I am in the process of attempting to create a column which tells me the difference between the time the log was created in elastic (so the ingestion time stamp) and the timestamp against my IIS log(so the iis.access.time).

This is currently what i have in my SCRIPT pipline.

```auto
def ingested = ctx.event.ingested;

def created = ctx.iis.access.time;

ingested = ZonedDateTime.parse(ingested);

ctx.event.ingestionspeed = ChronoUnit.SECONDS.between(created, ingested);

```

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![matw](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matw/32/13913_2.png) [@matw](https://discuss.elastic.co/u/matw)\
**Post date:** [October 15, 2021, 2:26pm UTC](https://discuss.elastic.co/t/trying-to-compare-two-timestamps-to-calculate-ingestion-speed/286823/2 "2021-10-15T14:26:18Z")

</div>

Hi

So while this is more a Elasticsearch topic, I try to help , didn't test, but I think you need also to parse `ctx.iis.access.time` before you can calculate the seconds between created and ingested?

BTW you could also do it with a runtime field:

> **[Runtime fields | Elasticsearch Guide \[master\] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/master/runtime.html)**

but of course, doing it before document is ingested is better for performance.

Best,  
Matthias

---

<div class="post-metadata">

**Author:** ![jamesm1](https://avatars.discourse-cdn.com/v4/letter/j/ce7236/32.png) [@jamesm1](https://discuss.elastic.co/u/jamesm1)\
**Post date:** [October 15, 2021, 2:58pm UTC](https://discuss.elastic.co/t/trying-to-compare-two-timestamps-to-calculate-ingestion-speed/286823/3 "2021-10-15T14:58:52Z")

</div>

Hello - Thank you for your response.  
I have managed to do what i needed in the end. by converting both to a datetime I was then able to compare the two and get the difference.

---

<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 12, 2021, 2:59pm UTC](https://discuss.elastic.co/t/trying-to-compare-two-timestamps-to-calculate-ingestion-speed/286823/4 "2021-11-12T14:59:32Z")

</div>

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