# How to store array in elasticsearch from logstash

**URL:** https://discuss.elastic.co/t/how-to-store-array-in-elasticsearch-from-logstash/87445
**Category:** Logstash
**Created:** [May 29, 2017, 12:28pm UTC](https://discuss.elastic.co/t/how-to-store-array-in-elasticsearch-from-logstash/87445 "2017-05-29T12:28:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![abhi\_chinchole](https://avatars.discourse-cdn.com/v4/letter/a/d6d6ee/32.png) [@abhi\_chinchole](https://discuss.elastic.co/u/abhi_chinchole)
#### Post date: [May 29, 2017, 12:28pm UTC](https://discuss.elastic.co/t/how-to-store-array-in-elasticsearch-from-logstash/87445/1 "2017-05-29T12:28:12Z")

</div>

I am trying to store data in array field of elasticsearch from logstash  
Raw JSON event :

> {"user-metadata":{"tags":["BCT-LTP-G109","Elasticsearch","logstash"]},"data":"abc def xyz"}

I want to take "tags" field out as a separate field with name "user\_tags" and then store this into elasticsearch.  
Current Logstash config: Filter Part

> mutate {  
> add\_field =\> { "user\_tags" =\> "%{user-metadata[tags]}" }  
> }   
> mutate {   
> gsub =\> [   
> "user\_tags", "," ,'","',  
> "user\_tags", "^" ,'["',  
> "user\_tags", "$" ,'"]'   
> ]   
> }

---

<div class="post-metadata">

### Author: ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)
#### Post date: [May 29, 2017, 7:48pm UTC](https://discuss.elastic.co/t/how-to-store-array-in-elasticsearch-from-logstash/87445/2 "2017-05-29T19:48:09Z")

</div>

Hmm, yes. Logstash's configuration language isn't very good at this. I'd use a ruby filter. This code should work:

```
event.set('user_tags', event.get('[user-metadata][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: [June 26, 2017, 7:48pm UTC](https://discuss.elastic.co/t/how-to-store-array-in-elasticsearch-from-logstash/87445/3 "2017-06-26T19:48:25Z")

</div>

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