# Logstash. Get fields by position number

**URL:** <https://discuss.elastic.co/t/logstash-get-fields-by-position-number/2775>\
**Category:** Logstash\
**Created:** [June 16, 2015, 9:54am UTC](https://discuss.elastic.co/t/logstash-get-fields-by-position-number/2775 "2015-06-16T09:54:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Paul\_Letski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_letski/32/671_2.png) [@Paul\_Letski](https://discuss.elastic.co/u/Paul_Letski)\
**Post date:** [June 16, 2015, 9:54am UTC](https://discuss.elastic.co/t/logstash-get-fields-by-position-number/2775/1 "2015-06-16T09:54:53Z")

</div>

**Background**

I have the scheme: logs from my app go through rsyslog to central log server, then to Logstash and Elasticsearch. Logs from app is a pure JSON, but rsyslog adds to log "timestamp", "app name" and "server name" fileds. And log becomes to this:

```
timestamp app-name server-name [JSON]

```

**Question**

How can I remove first three fields with Logstash filters? Can I get fields by position numbers (like in awk) and do something like:

```
filter {
  somefilter_name {
      remove_field => $1, $2, $3 
  }
}

```

Or maybe my vision is totally wrong and I must do this in another way?

Thank you!

---

<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:** [June 17, 2015, 4:11am UTC](https://discuss.elastic.co/t/logstash-get-fields-by-position-number/2775/2 "2015-06-17T04:11:32Z")

</div>

Do you want to remove them completely or just from the message part?

You can use [mutate](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html) to do either.

---

<div class="post-metadata">

**Author:** ![Paul\_Letski](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/paul_letski/32/671_2.png) [@Paul\_Letski](https://discuss.elastic.co/u/Paul_Letski)\
**Post date:** [June 17, 2015, 1:42pm UTC](https://discuss.elastic.co/t/logstash-get-fields-by-position-number/2775/3 "2015-06-17T13:42:56Z")

</div>

I want to remove them completely.  
I got an advice on stackoverflow to use filter like this:

```
grok {
     pattern => "%{TIMESTAMP_ISO8601:timestamp} %{WORD:app} %{WORD:server} %{GREEDYDATA:message}"
     overwrite => ["message"]
}

json {
    source => "message"
}

```

But now I'm getting error in log about "Trouble parsing json".

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [June 25, 2015, 7:31pm UTC](https://discuss.elastic.co/t/logstash-get-fields-by-position-number/2775/4 "2015-06-25T19:31:54Z")

</div>

Well, what does the `message` field that you're trying to parse as JSON look like?

---

<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:** [July 6, 2017, 5:36am UTC](https://discuss.elastic.co/t/logstash-get-fields-by-position-number/2775/5 "2017-07-06T05:36:27Z")

</div>


