# Read csv file and insert/update the index based on condition in logstash

**URL:** <https://discuss.elastic.co/t/read-csv-file-and-insert-update-the-index-based-on-condition-in-logstash/94497>\
**Category:** Logstash\
**Created:** [July 25, 2017, 2:44pm UTC](https://discuss.elastic.co/t/read-csv-file-and-insert-update-the-index-based-on-condition-in-logstash/94497 "2017-07-25T14:44:56Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![skodari](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skodari/32/19875_2.png) [@skodari](https://discuss.elastic.co/u/skodari)\
**Post date:** [July 25, 2017, 2:44pm UTC](https://discuss.elastic.co/t/read-csv-file-and-insert-update-the-index-based-on-condition-in-logstash/94497/1 "2017-07-25T14:44:56Z")

</div>

Hi folks,  
I have quick qusetion.  
My scenario is read csv file and insert/update the index based on condition  
here my query,  
I need to filter 'age' field from csv file and check if the age \> 18, then only I should update/insert field in the index/total index

input {  
file {  
path =\> "C:/ElasticSearch/logstash-5.3.2/logstash-5.3.2/data/createmember.txt"  
start\_position =\> "beginning"  
type =\> "createmember"  
}  
}

filter {  
csv {  
columns =\> ["memberid","firstname","lastname","age","status"]  
separator =\> ","  
}

```
             ruby{ 
                   #do something to validate input age(age>18) to set status in index 
                     **?????**
                  }

```

}

output {  
stdout { codec =\> rubydebug }  
elasticsearch{  
hosts =\> ["localhost:9200"]  
index =\> "createmember"  
document\_type =\> "createmember"  
document\_id =\> "%{member\_id}%{first\_name}%{last\_name}%{age}%{status}   
doc\_as\_upsert =\> "true"  
}  
}

thanks

---

<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:** [July 26, 2017, 8:04am UTC](https://discuss.elastic.co/t/read-csv-file-and-insert-update-the-index-based-on-condition-in-logstash/94497/2 "2017-07-26T08:04:37Z")

</div>

You don't need a ruby filter.

```nohighlight
if [age] > 18 {
  # whatever
}

```

This assumes that `age` is a numeric field. You can tweak the csv filter to make that column numeric or you can use a mutate filter to convert the field value.

---

<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:** [August 23, 2017, 8:05am UTC](https://discuss.elastic.co/t/read-csv-file-and-insert-update-the-index-based-on-condition-in-logstash/94497/3 "2017-08-23T08:05:07Z")

</div>

Closed on August 23, 2017, 8:05am UTC

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