# Grok filter and split message

**URL:** <https://discuss.elastic.co/t/grok-filter-and-split-message/128654>\
**Category:** Logstash\
**Created:** [April 19, 2018, 8:12am UTC](https://discuss.elastic.co/t/grok-filter-and-split-message/128654 "2018-04-19T08:12:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arkady\_renko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arkady_renko/32/30160_2.png) [@arkady\_renko](https://discuss.elastic.co/u/arkady_renko)\
**Post date:** [April 19, 2018, 8:12am UTC](https://discuss.elastic.co/t/grok-filter-and-split-message/128654/1 "2018-04-19T08:12:45Z")

</div>

Hello,

I want to put my java app logs into elasticsearch.  
Filebeat sends logs to logstash reads the log file. I checked my grok filter at [http://grokdebug.herokuapp.com/](http://grokdebug.herokuapp.com/) and looks OK. But in elastic search there is only message field.  
How can add other fields?

Thanks in advance.

Sample log line:  
INFO 2016-04-17 16:32:03.805 REST ID-28033d4aa1b9-45637-1524041105852-2-1 905497479867 121212 ABC aaa  
My logstash configuration and document in es.

```
input {
  beats {
    port => 5044
  }
}

filter {
  if [type] == "log" {
    grok {
      match => { "message" => "%{LOGLEVEL:level}\s+%{TIMESTAMP_ISO8601:sent_time}\s+%{NOTSPACE:frontend}\s+%{NOTSPACE:trx_id}\s+%{NOTSPACE:msisdn}\s+%{NOTSPACE:shortCode}\s+%{NOTSPACE:msgBody}\s+%{NOTSPACE:productId}" }
    }
  }
}

    output {
      elasticsearch {
        codec => "json"
        hosts => ["localhost:9200"]
        index => "sms_index"
      }
    }

      {
        "_index" : "sms_index",
        "_type" : "doc",
        "_id" : "jyn12mIBa-TikyX2irr5",
        "_score" : 1.0,
        "_source" : {
          "message" : "INFO 2016-04-17 16:32:03.805 REST ID-28033d4aa1b9-45637-1524041105852-2-1 905497479867 121212 ABC aaa",
          "source" : "/opt/jboss-fuse-6.3.0.redhat-283/data/log/smsquery.log",
          "@timestamp" : "2018-04-18T22:52:26.240Z",
          "host" : "sscmdev",
          "beat" : {
            "version" : "6.2.3",
            "name" : "sscmdev",
            "hostname" : "sscmdev"
          },
          "prospector" : {
            "type" : "log"
          },
          "tags" : [
            "beats_input_codec_plain_applied"
          ],
          "@version" : "1",
          "offset" : 204
        }
      }
```

---

<div class="post-metadata">

**Author:** ![paz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paz/32/28003_2.png) [@paz](https://discuss.elastic.co/u/paz)\
**Post date:** [April 20, 2018, 10:48am UTC](https://discuss.elastic.co/t/grok-filter-and-split-message/128654/2 "2018-04-20T10:48:01Z")

</div>

Your filtering condition is wrong here

```auto
filter {
  if [type] == "log" {
    grok {
      match => { "message" => "%{LOGLEVEL:level}\s+%{TIMESTAMP_ISO8601:sent_time}\s+%{NOTSPACE:frontend}\s+%{NOTSPACE:trx_id}\s+%{NOTSPACE:msisdn}\s+%{NOTSPACE:shortCode}\s+%{NOTSPACE:msgBody}\s+%{NOTSPACE:productId}" }
    }
  }
}
```

There is no _type_ field in top level of the document, it's nested under _prospector_, Try changing the condtion to

```auto
if [prospector][type] == "log" {
```

---

<div class="post-metadata">

**Author:** ![arkady\_renko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/arkady_renko/32/30160_2.png) [@arkady\_renko](https://discuss.elastic.co/u/arkady_renko)\
**Post date:** [April 20, 2018, 8:52pm UTC](https://discuss.elastic.co/t/grok-filter-and-split-message/128654/3 "2018-04-20T20:52:11Z")

</div>

> [@paz](#):
>
> [prospector]

Thank you very much. It works fine.

---

<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:** [May 18, 2018, 8:52pm UTC](https://discuss.elastic.co/t/grok-filter-and-split-message/128654/4 "2018-05-18T20:52:15Z")

</div>

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