# Change event name based on type

**URL:** https://discuss.elastic.co/t/change-event-name-based-on-type/284129
**Category:** Logstash
**Created:** [September 13, 2021, 10:22pm UTC](https://discuss.elastic.co/t/change-event-name-based-on-type/284129 "2021-09-13T22:22:00Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![antonisnyc94](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antonisnyc94/32/94316_2.png) [@antonisnyc94](https://discuss.elastic.co/u/antonisnyc94)
#### Post date: [September 13, 2021, 10:22pm UTC](https://discuss.elastic.co/t/change-event-name-based-on-type/284129/1 "2021-09-13T22:22:00Z")

</div>

Hello,

I am having a field which is an object but sometimes it's a string. I'm using the below ruby code but for some reason im still getting an error.. Does anyone know why?

```auto
if event.get("[data][aws][configuration][status]").is_a? String
                          event.set("[data][aws][configuration][statusString]", event.get("[data][aws][configuration][status]"))
                          event.remove("[data][aws][configuration][status]")
elsif event.get("[data][aws][configuration][status]").nil?
                          event.remove("[data][aws][configuration][status]")
end

```

Event:

```auto
{
               "data" => {
        "integration" => "aws",
                "aws" => {
                           "configuration" => {
                                          "status" => "available",
            }
        }
    }
}

```

Error:  
`[WARN] 2021-09-13 21:28:34.001 [[main]>worker0] amazonelasticsearch - Could not index event to Elasticsearch. {:status=>400, :action=>["index", {:_id=>nil, :_index=>"wazuh-alerts-4.x-2021.37", :_type=>"_doc", :_routing=>nil}, #<LogStash::Event:0x67f05c56>], :response=>{"index"=>{"_index"=>"wazuh-alerts-4.x-2021.37", "_type"=>"_doc", "_id"=>"wfQP4XsBhi2ZIJK3ywFq", "status"=>400, "error"=>{"type"=>"mapper_parsing_exception", "reason"=>"object mapping for [data.aws.configuration.status] tried to parse field [status] as object, but found a concrete value"}}}}`

Thanks in advance!

---

<div class="post-metadata">

### Author: ![antonisnyc94](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/antonisnyc94/32/94316_2.png) [@antonisnyc94](https://discuss.elastic.co/u/antonisnyc94)
#### Post date: [September 14, 2021, 12:48pm UTC](https://discuss.elastic.co/t/change-event-name-based-on-type/284129/2 "2021-09-14T12:48:30Z")

</div>

Please note that I troubleshooted it by using a "puts" function within the logical statement, and the logical statement works as expected..

For now im using a workaround to find whether the fields are not objects but i'd really like to know as to why the ruby statements didnt work..

```auto
  if [data][aws][configuration][status] =~ /^((?!^{.*}).)*$/ {
                      mutate {
                        rename => {"[data][aws][configuration][status]" => "[data][aws][configuration][statusString]"}
                      }
                  }

```

---

<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: [October 12, 2021, 12:49pm UTC](https://discuss.elastic.co/t/change-event-name-based-on-type/284129/3 "2021-10-12T12:49:13Z")

</div>

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