# To modify multiple field names through logstash

**URL:** <https://discuss.elastic.co/t/to-modify-multiple-field-names-through-logstash/279876>\
**Category:** Logstash\
**Created:** [July 28, 2021, 2:39pm UTC](https://discuss.elastic.co/t/to-modify-multiple-field-names-through-logstash/279876 "2021-07-28T14:39:31Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![raju.d](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@raju.d](https://discuss.elastic.co/u/raju.d)\
**Post date:** [July 28, 2021, 2:39pm UTC](https://discuss.elastic.co/t/to-modify-multiple-field-names-through-logstash/279876/1 "2021-07-28T14:39:31Z")

</div>

Hello,

I came across an old discussion -\> [Rename or Change Available Fields](https://discuss.elastic.co/t/rename-or-change-available-fields/188035) . Unfortunately in that discussion, the final configuration that worked has not been shared!  
I am working on same and wanted to get rid of jsonPayload from the beginning of all fields that starts with it. Basically I just want to remove it.  
Per my understanding, by using mutate plugin it doesn't allow to use regex and replace the name of multiple fields.  
Also, is there a way to change all upper case field names to lower case.

I am using ES version 7.13.1. Sending logs from google cloud using logstash\_pubsub plugin and then passing it through the json filter to parse it and split into more detailed fields.  
My current config is very simple

```auto
      input {
        google_pubsub {
            project_id => "project-name"
            topic => "topic-name-woith-logs"
            subscription => "topic-subscription-name"
            json_key_file => "/etc/logstash/keys/logstash-sa.json"
        }
      }
      filter {
        json {
          source => "message"
          tag_on_failure => ["_jsonparsefailure"]
          skip_on_invalid_json => true
          remove_field => ["message"]
        }

       # to omit publishing cloudaudit logs to ES
       if "cloudaudit.googleapis.com" in [logName] { drop { } }
      }

      output {
        elasticsearch {
          cloud_id => "${ELASTIC_CLOUD_ID}"
          cloud_auth => "${ELASTIC_CLOUD_AUTH}"
          index => "logs-%{[resource][labels][project_id]}_%{[resource][labels][namespace_name]}-%{+YYYY.MM.dd}"
        }
      }

```

Can some one please help me ?

---

<div class="post-metadata">

**Author:** ![Cad](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cad/32/86661_2.png) [@Cad](https://discuss.elastic.co/u/Cad)\
**Post date:** [July 28, 2021, 3:28pm UTC](https://discuss.elastic.co/t/to-modify-multiple-field-names-through-logstash/279876/2 "2021-07-28T15:28:06Z")

</div>

Hi,

If you know the name of the fields in advance, you can use the lowercase option of the mutate plugin documentation [here](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-lowercase).

If you don't know the name of the fields in advance, use a ruby script should be the best solution.  
A code already exist [here](https://discuss.elastic.co/t/lowercase-all-fields-and-sub-fields/174438/2). If you want to remove `jsonPayload.` from the beginning of all fields, edit this line of code `event.set(k.downcase, processObject(v))` to this

```auto
event.set(k.downcase.gsub(/jsonpayload\./, ''), processObject(v))
event.remove(k)

```

(the second parameter of gsub is 2 single quotes)

---

<div class="post-metadata">

**Author:** ![raju.d](https://avatars.discourse-cdn.com/v4/letter/r/a4c791/32.png) [@raju.d](https://discuss.elastic.co/u/raju.d)\
**Post date:** [August 5, 2021, 7:38am UTC](https://discuss.elastic.co/t/to-modify-multiple-field-names-through-logstash/279876/3 "2021-08-05T07:38:36Z")

</div>

Thanks for the suggestion Cad!

I have tried using the script, as below  
enabled it

```auto
      filter {
        ruby {
          path => "/etc/logstash/filters/script.rb"
        }
      }

```

Then mounted it using a configmap. I could confirm that all field names are changed to lower case and also jsonPayload from beginning of field names have been removed.

---

<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:** [September 2, 2021, 7:39am UTC](https://discuss.elastic.co/t/to-modify-multiple-field-names-through-logstash/279876/4 "2021-09-02T07:39:18Z")

</div>

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