# How to use split filter on the field using logstash

**URL:** <https://discuss.elastic.co/t/how-to-use-split-filter-on-the-field-using-logstash/169725>\
**Category:** Logstash\
**Created:** [February 24, 2019, 1:48pm UTC](https://discuss.elastic.co/t/how-to-use-split-filter-on-the-field-using-logstash/169725 "2019-02-24T13:48:55Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![muralasandeep](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@muralasandeep](https://discuss.elastic.co/u/muralasandeep)\
**Post date:** [February 24, 2019, 1:48pm UTC](https://discuss.elastic.co/t/how-to-use-split-filter-on-the-field-using-logstash/169725/1 "2019-02-24T13:48:55Z")

</div>

Hi everyone ,  
i am new at logstash here i am trying to fatch data from .csv file and i have 6 fields total and in that 6 fields one field have actually data i need to split that field as multiple fields ,  
here is my config file  
input{  
file{  
path =\> "/home/.csv"  
start\_position =\> "beginning"  
sincedb\_path =\> "/div/null"  
}  
}  
filter{  
csv{  
separator =\> ","  
columns =\>["log\_id","log\_datetime","log\_type","log\_messagge","log\_componet","log\_user"]  
}  
date{  
match =\> ["log\_datetime","yyyy-MM-dd HH:MM:ss]  
}  
mutate { convert =\> ["log\_id","integer"]}  
}  
split{ field =\> "log\_message"}

output{  
elasticsearch{  
hosts =\> "[http://localhost:9200](http://localhost:9200)"  
index =\> "logs\_data"  
}  
stdout{}  
}

in log\_message field my data is like "data": [{ "field1":"string","field2":"string"...},{ "field1":"string","field2":"string"...}  
and another row is like (field-\>"value") (field-\>"value")

here my problem is how can i split this log\_message field into multiple fields ,  
help me please ,thanks you

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [February 24, 2019, 2:23pm UTC](https://discuss.elastic.co/t/how-to-use-split-filter-on-the-field-using-logstash/169725/2 "2019-02-24T14:23:40Z")

</div>

A split filter is used to split a message into multiple message, each containing one element from an array. If you want to split a string into an array then use the [split](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html#plugins-filters-mutate-split) option on a mutate filter. However, I don't think either is useful here.

It looks like in some cases log\_message is almost a JSON array, and in some cases it is key-value pairs. If so, the kv case could be parsed using

```
kv { field_split_pattern => "[\( \)]+" value_split_pattern => "->" }

```

In the other case you can use mutate to convert it into valid JSON, and then use a [json](https://www.elastic.co/guide/en/logstash/current/plugins-filters-json.html) filter.

```
mutate { gsub => ["message", "^", "{", "message", "$", "}"] }
```

---

<div class="post-metadata">

**Author:** ![muralasandeep](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@muralasandeep](https://discuss.elastic.co/u/muralasandeep)\
**Post date:** [February 26, 2019, 9:59am UTC](https://discuss.elastic.co/t/how-to-use-split-filter-on-the-field-using-logstash/169725/3 "2019-02-26T09:59:16Z")

</div>

Hi @Badger,  
Thank you so much for your reply,

I am getting the data when i use  
kv { field\_split\_pattern =\> "[( )]+" value\_split\_pattern =\> "-\>" }  
but in my log\_message field some rows are like this  
"(Institution Id-\>77) (data Id-\>127) QUERY-\>SQL query ERROR-\>Table 'tablename' doesn't exist"  
and some are  
"QUERY-\> update set tablename column=value some conditions  
ERROR: Table 'Table name' doesn't exist"

if i apply your "kv" filter plugins i am getting the results like this ,  
{  
"ERROR" =\> "Table", //here i am getting only first word  
"QUERY" =\> "insert", //here also  
"Id"=\>[  
"77", //here i need field name i need  
"127" //here also  
]  
},  
{  
"ERROR" =\> "Table", //here i am getting only first word  
"QUERY" =\> "update", //here also  
}  
but here my expected result is  
{  
"ERROR" =\> "Table 'table name or column name' doesn't exist",  
"QUERY" =\> "insert query", //i need total query here not only insert command  
"institution Id"=\>77,  
"data Id" =\> 127  
}  
please help me thank you

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [February 26, 2019, 12:20pm UTC](https://discuss.elastic.co/t/how-to-use-split-filter-on-the-field-using-logstash/169725/4 "2019-02-26T12:20:20Z")

</div>

The problem is that space is used to separate fields but also occurs within fields. I don't see any way to unambiguously parse that.

---

<div class="post-metadata">

**Author:** ![muralasandeep](https://avatars.discourse-cdn.com/v4/letter/m/73ab20/32.png) [@muralasandeep](https://discuss.elastic.co/u/muralasandeep)\
**Post date:** [February 27, 2019, 4:16am UTC](https://discuss.elastic.co/t/how-to-use-split-filter-on-the-field-using-logstash/169725/5 "2019-02-27T04:16:13Z")

</div>

Hi @Badger ,  
Thank you very much for your reply,  
i do not know how to solve this problem ,i am new to this logstash ,can you explain what should i do .

Thanks  
Sandeep

---

<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 27, 2019, 4:16am UTC](https://discuss.elastic.co/t/how-to-use-split-filter-on-the-field-using-logstash/169725/6 "2019-03-27T04:16:37Z")

</div>

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