# Logstash ignores my if condition

**URL:** <https://discuss.elastic.co/t/logstash-ignores-my-if-condition/154066>\
**Category:** Logstash\
**Created:** [October 25, 2018, 9:08pm UTC](https://discuss.elastic.co/t/logstash-ignores-my-if-condition/154066 "2018-10-25T21:08:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rtfm.pls](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rtfm.pls/32/36942_2.png) [@rtfm.pls](https://discuss.elastic.co/u/rtfm.pls)\
**Post date:** [October 25, 2018, 9:08pm UTC](https://discuss.elastic.co/t/logstash-ignores-my-if-condition/154066/1 "2018-10-25T21:08:53Z")

</div>

Some of input log messages are in JSON format. I would like to use "time" value as "@timestamp".

This is an example of log message in JSON format :

```json
{
  "level":30,
  "time":1531171074631,
  "msg":"hello world",
  "pid":657,
  "hostname":"Davids-MBP-3.fritz.box",
  "v":1
}

```

Here is my logstash configuration file:

```auto
input {
  beats {
    ...
  }
}

filter{
  json {
    source => "message"
    target => "json_message"
    skip_on_invalid_json => true
    tag_on_failure => [""]
  }

  if [json_message][time] {
    mutate {
      convert => { "[json_message][time]" => "string" }
    }

    date {
      match => ["[json_message][time]", "UNIX"]
      timezone => "UTC"
      target => "@timestamp"
    }
  }
}

output {
  elasticsearch {
    ...
  }
}

```

I have no luck with this configuration: key [json\_message][time] still has number format and it looks like it is not used as @timestamp.

Can someone point to my mistake?

---

<div class="post-metadata">

**Author:** ![rtfm.pls](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rtfm.pls/32/36942_2.png) [@rtfm.pls](https://discuss.elastic.co/u/rtfm.pls)\
**Post date:** [October 25, 2018, 10:23pm UTC](https://discuss.elastic.co/t/logstash-ignores-my-if-condition/154066/2 "2018-10-25T22:23:38Z")

</div>

Sorry, i should use "UNIX\_MS" not "UNIX" time format in logstash configuration file.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 26, 2018, 12:07am UTC](https://discuss.elastic.co/t/logstash-ignores-my-if-condition/154066/3 "2018-10-26T00:07:23Z")

</div>

Thanks for sharing the solution 😃

---

<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 23, 2018, 12:07am UTC](https://discuss.elastic.co/t/logstash-ignores-my-if-condition/154066/4 "2018-11-23T00:07:24Z")

</div>

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