# Logstash mutate nested dynamic field path

**URL:** <https://discuss.elastic.co/t/logstash-mutate-nested-dynamic-field-path/320594>\
**Category:** Logstash\
**Created:** [December 6, 2022, 2:40pm UTC](https://discuss.elastic.co/t/logstash-mutate-nested-dynamic-field-path/320594 "2022-12-06T14:40:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shrouk\_Negm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shrouk_negm/32/103180_2.png) [@Shrouk\_Negm](https://discuss.elastic.co/u/Shrouk_Negm)\
**Post date:** [December 6, 2022, 2:40pm UTC](https://discuss.elastic.co/t/logstash-mutate-nested-dynamic-field-path/320594/1 "2022-12-06T14:40:13Z")

</div>

logstash add field from third level BUT second level name is dynamic based on another field value  
like the bellow example entityType value depending on serviceName value so how should i do it

```auto
input {
  kafka{
    codec => json
    bootstrap_servers => "localhost:9092"
    topics => ["PO_CREATE_EVENT"]
  }
}

filter {
mutate {
	 

	 add_field => {
        "entityType" => "%{[event][%{[serviceName]}][@type]}"
      }
	 add_field => {
		"entityId" => "%{[event][productOrder][id]}"
	  }
	  add_field => {
        "eventName" => "%{[eventType]}"
      }
	  add_field => {
        "[auth][requestOrigin]" => "%{[originIp]}"
      }
	  
      remove_field => ["[auth][authenticationToken]","event","eventType","originIp","@version","@timestamp"]
    } 

}

output {
  stdout { codec => rubydebug } 
  elasticsearch {
      hosts => ["localhost:9200"]
      index => "dnext-audit-log-events"
  }
}

```

---

<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:** [January 3, 2023, 2:41pm UTC](https://discuss.elastic.co/t/logstash-mutate-nested-dynamic-field-path/320594/2 "2023-01-03T14:41:08Z")

</div>

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