# Convert a metadata String field into array

**URL:** <https://discuss.elastic.co/t/convert-a-metadata-string-field-into-array/156663>\
**Category:** Logstash\
**Created:** [November 14, 2018, 1:06pm UTC](https://discuss.elastic.co/t/convert-a-metadata-string-field-into-array/156663 "2018-11-14T13:06:54Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Panda8](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda8/32/69427_2.png) [@Panda8](https://discuss.elastic.co/u/Panda8)\
**Post date:** [November 14, 2018, 1:06pm UTC](https://discuss.elastic.co/t/convert-a-metadata-string-field-into-array/156663/1 "2018-11-14T13:06:54Z")

</div>

Hi

I have an HTTP JSON Input as follows :  
{  
"mapping": {  
"index": "indexname",  
"activity": {  
"action": "script\_update",  
"fieldList": ["field1","field2"]  
},  
"document\_type": "\_doc",  
"document\_id": "1",  
"routing": "1"  
}  
}

I have converted the above data in @metadata fields as it was not needed in final elasticsearch output.  
Now I need to run a script in which I need to iterate on the "fieldList" array of @metadata and access each element as seperate String.

Currently I am unable to convert the String to array of comma separated string (from @metadata).

I have tried using mutate + split filter but it didn't work.

```
    input{
	http {
		host => "127.0.0.1"
		port => 8080
	}
}
filter{
	mutate{
		add_field => { 
			"[@metadata][index]" => "%{[mapping][index]}" 
		}
	}	
	mutate{
		add_field => { 
			"[@metadata][action]" => "%{[mapping][activity][action]}" 
		}
	}
	mutate{
		add_field => { 
			"[@metadata][fieldlist]" => "%{[mapping][activity][fieldlist]}" 
		}
	}

	mutate{
		add_field => { 
			"[@metadata][userId]" => "%{[mapping][activity][userId]}" 
		}
	}
	mutate{
		add_field => {	
			"[@metadata][document_id]" => "%{[mapping][document_id]}" 
		}
	}
	mutate{
		add_field => { 
			"[@metadata][document_type]" => "%{[mapping][document_type]}" 
		}
	}	
	mutate{
		add_field => {	
			"[@metadata][routing]" => "%{[mapping][routing]}" 
		}
	}
}
output{

	  if [@metadata][action] == "script_update" {
			stdout { codec => rubydebug { metadata => true }} 
			
			elasticsearch{
				hosts => ["localhost:9200"]
				index => "%{[@metadata][index]}"
				document_type => "%{[@metadata][document_type]}"
				document_id => "%{[@metadata][document_id]}"
				routing => "%{[@metadata][routing]}"
				action => "update"
				script_lang => "painless"
				script_type => "inline" 
				script => ' ' 
                           /* Add script to iterate on field list and update the corresponding field in elasticsearch with value 2 */
				}
			}	
}	 

```

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![Panda8](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/panda8/32/69427_2.png) [@Panda8](https://discuss.elastic.co/u/Panda8)\
**Post date:** [November 16, 2018, 12:54pm UTC](https://discuss.elastic.co/t/convert-a-metadata-string-field-into-array/156663/2 "2018-11-16T12:54:21Z")

</div>

Any update on this ?

---

<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:** [December 14, 2018, 12:54pm UTC](https://discuss.elastic.co/t/convert-a-metadata-string-field-into-array/156663/3 "2018-12-14T12:54:28Z")

</div>

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