# How can I add an array object to tags using add\_Tag

**URL:** https://discuss.elastic.co/t/how-can-i-add-an-array-object-to-tags-using-add-tag/73676
**Category:** Logstash
**Created:** [February 2, 2017, 12:39pm UTC](https://discuss.elastic.co/t/how-can-i-add-an-array-object-to-tags-using-add-tag/73676 "2017-02-02T12:39:19Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![trondhindenes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trondhindenes/32/10534_2.png) [@trondhindenes](https://discuss.elastic.co/u/trondhindenes)
#### Post date: [February 2, 2017, 12:39pm UTC](https://discuss.elastic.co/t/how-can-i-add-an-array-object-to-tags-using-add-tag/73676/1 "2017-02-02T12:39:19Z")

</div>

I have the following logstash snippet:

```
elseif [Properties][Telemetry] {
	  mutate {
		update => { "logtype" => "telemetry" }
		add_field => {
		  "key" => "%{[Properties][Telemetry][Key]}"
		  "value" => "%{[Properties][Telemetry][Value]}"
		  "component" => "%{[Properties][Component]}"
		  "test_tags" => "%{[Properties][Telemetry][Tags]}" 
		  #"test_tags" => "hello, yello" 
		}
	  }
	  mutate {
		split => { "test_tags" => "," }
	  }
	  mutate {
		strip => ["test_tags"]
	  }
	  mutate {
		add_tag => ["telemetry"]
		add_tag => ["%{test_tags}"]
	  }
	  mutate {
		remove_field => "Properties"
		lowercase => ["key"]
	  }
}

```

The value of [Properties][Telemetry][Tags] is a comma-separated list, and I want each item to end up in "tags" as a separate item. Using split I'm able to get "test\_tags" to show up as an array, but no matter what I do I can't seem to add each item of that field to tags using add\_tags. Any suggestion welcome! Sample output of my current filter:

```
{                                                                                                                 
           "Level" => "Information",                                                                              
        "@version" => "1",                                                                                        
      "@timestamp" => "2017-02-01T17:59:33.842Z",                                                                 
          "source" => "C:\\Logstashtest\\logs\\Services.Metadata.MessageHandler-20170201.txt",             
          "fields" => nil,                                                                                        
          "offset" => 2780,                                                                                       
            "type" => "log",                                                                                      
      "input_type" => "log",                                                                                      
           "count" => 1,                                                                                          
            "beat" => {                                                                                           
        "hostname" => "DESKTOP-5E16B28",                                                                          
            "name" => "DESKTOP-5E16B28"                                                                           
    },                                                                                                            
            "tags" => [                                                                                           
        [0] "win2012r2",                                                                                          
        [1] "beats_input_codec_json_applied",                                                                     
        [2] "telemetry",                                                                                          
        [3] "channel:nrk,channel:123,message:AddAssets"                                                           
    ],                                                                                                            
            "host" => "DESKTOP-5E16B28",                                                                          
         "logtype" => "telemetry",                                                                                
            "hour" => "17",                                                                                       
    "computername" => "WM14",                                                                                     
    "messagelevel" => "Information",                                                                              
             "key" => "assetsrecievedonbus",                                                                      
           "value" => 6,                                                                                          
       "component" => "Services.Metadata.MessageHandler",                                                  
       "test_tags" => [                                                                                           
        [0] "channel:nrk",                                                                                        
        [1] "channel:123",                                                                                        
        [2] "message:AddAssets"                                                                                   
    ]                                                                                                             
}
```

---

<div class="post-metadata">

### Author: ![terje](https://avatars.discourse-cdn.com/v4/letter/t/848f3c/32.png) [@terje](https://discuss.elastic.co/u/terje)
#### Post date: [February 2, 2017, 1:58pm UTC](https://discuss.elastic.co/t/how-can-i-add-an-array-object-to-tags-using-add-tag/73676/2 "2017-02-02T13:58:23Z")

</div>

```
ruby {
    code => "
      tags = event.get('tags')
      (tags ||= []).concat(event.get('test_tags'))
      event.set('tags', tags)
    "
}
```

---

<div class="post-metadata">

### Author: ![trondhindenes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trondhindenes/32/10534_2.png) [@trondhindenes](https://discuss.elastic.co/u/trondhindenes)
#### Post date: [February 2, 2017, 5:07pm UTC](https://discuss.elastic.co/t/how-can-i-add-an-array-object-to-tags-using-add-tag/73676/3 "2017-02-02T17:07:15Z")

</div>

Thanks! It doesnt work on my test env unfortunately, "concat" is not understood.

---

<div class="post-metadata">

### Author: ![trondhindenes](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trondhindenes/32/10534_2.png) [@trondhindenes](https://discuss.elastic.co/u/trondhindenes)
#### Post date: [February 2, 2017, 5:28pm UTC](https://discuss.elastic.co/t/how-can-i-add-an-array-object-to-tags-using-add-tag/73676/4 "2017-02-02T17:28:02Z")

</div>

The solution turned out to be rather simple:  
mutate {  
split =\> { "extra\_tags" =\> "," }  
}  
mutate {  
merge =\> { "tags" =\> "extra\_tags" }  
}

---

<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: [March 2, 2017, 5:28pm UTC](https://discuss.elastic.co/t/how-can-i-add-an-array-object-to-tags-using-add-tag/73676/5 "2017-03-02T17:28:30Z")

</div>

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