# 【Logstash】 I want to calculate the difference of field value

**URL:** <https://discuss.elastic.co/t/logstash-i-want-to-calculate-the-difference-of-field-value/206727>\
**Category:** Logstash\
**Created:** [November 6, 2019, 5:28am UTC](https://discuss.elastic.co/t/logstash-i-want-to-calculate-the-difference-of-field-value/206727 "2019-11-06T05:28:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yokoyoko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yokoyoko/32/57231_2.png) [@yokoyoko](https://discuss.elastic.co/u/yokoyoko)\
**Post date:** [November 6, 2019, 5:28am UTC](https://discuss.elastic.co/t/logstash-i-want-to-calculate-the-difference-of-field-value/206727/1 "2019-11-06T05:28:30Z")

</div>

# Prerequisite

Monitoring server access logs with logstash.

# want to do

Calculate the difference between the time field values ​​in the log (end\_time-start\_time). And I want to add the result to the new field as [support\_time].

### Log\_sample

【Before】  
"00001~Product inquiry~2019-11-05 10:00:00~2019-11-05 10:10:00"  
( [number)][business\_type)][service\_start\_time)][service\_end\_time])

【After】  
"00001~Product inquiry~2019-11-05 10:00:00~2019-11-05 10:10:00~ **00:10:00**"  
([number)][business\_type)][service\_start\_time)][service\_end\_time]**[support\_time]**)

### Code

```auto
# Adding a new field to the access log can be done with "add_field".
# But, The description method of end_time-start_time is not known.

    mutate {
     add_field => {
       "support_time" => "what to write here ?"
     }
    }

```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [November 6, 2019, 2:37pm UTC](https://discuss.elastic.co/t/logstash-i-want-to-calculate-the-difference-of-field-value/206727/2 "2019-11-06T14:37:24Z")

</div>

It will not be a mutate filter, you will need to use ruby.

---

<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 4, 2019, 2:37pm UTC](https://discuss.elastic.co/t/logstash-i-want-to-calculate-the-difference-of-field-value/206727/3 "2019-12-04T14:37:25Z")

</div>

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