# How to refer path from filter to other?

**URL:** <https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698>\
**Category:** Logstash\
**Created:** [June 2, 2015, 9:40am UTC](https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698 "2015-06-02T09:40:41Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Saket\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Saket\_Kumar](https://discuss.elastic.co/u/Saket_Kumar)\
**Post date:** [June 2, 2015, 9:40am UTC](https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698/1 "2015-06-02T09:40:41Z")

</div>

input {  
file {  
path =\> ["/opt/Log/\*.csv"]  
start\_position =\> "beginning"  
}  
}

i have requirement to use if [path] == "contains string" then set type =\> string.

Also can i refer path in other filters such as in Filter plugin and how.

thanks in advance.

---

<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:** [June 2, 2015, 9:57am UTC](https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698/2 "2015-06-02T09:57:58Z")

</div>

The path of the input file is saved in the `path` field so you can e.g. do this:

```
filter {
  if "substring" in [path] {
    mutate {
      replace => {
        "type" => "string"
      }
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![Saket\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Saket\_Kumar](https://discuss.elastic.co/u/Saket_Kumar)\
**Post date:** [June 2, 2015, 11:38am UTC](https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698/3 "2015-06-02T11:38:20Z")

</div>

Can i refer this [path] in ruby {}.

I have requirement to extract the file name from path and add\_field for them in elastic search...

the Ruby code what i have written:

def ReadFileName(filepath)  
filename = File.basename("#{filepath}", ".\*")  
value = filename.split("_")  
x = value[0]  
y = value[1]+"_" + value[2] +"\_"+ value[3]  
z = value[4]

print "#{x} \n"  
print "#{y} \n"  
print "#{z} \n"

return x,y,z  
end

ReadFileName("d:\1431509083921\_150513\_E6\_GHY\_bing\_CSV\_ContentBreakdown.csv")

Hence instead ReadFileName("d:\1431509083921\_150513\_E6\_GHY\_bing\_CSV\_ContentBreakdown.csv") can i refer ReadFileName("[path]")

---

<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:** [June 2, 2015, 11:58am UTC](https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698/4 "2015-06-02T11:58:22Z")

</div>

You don't have to use a ruby filter for this, but if you choose to do so you can access it with `event['path']`.

---

<div class="post-metadata">

**Author:** ![Saket\_Kumar](https://avatars.discourse-cdn.com/v4/letter/s/c57346/32.png) [@Saket\_Kumar](https://discuss.elastic.co/u/Saket_Kumar)\
**Post date:** [June 2, 2015, 12:03pm UTC](https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698/5 "2015-06-02T12:03:13Z")

</div>

what you suggest except ruby. i am sorry for being so demanding here...but i appreciate your help.

---

<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:** [June 2, 2015, 12:22pm UTC](https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698/6 "2015-06-02T12:22:36Z")

</div>

It's an ideal job for a [grok filter](https://www.elastic.co/guide/en/logstash/current/plugins-filters-grok.html).

---

<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:** [July 6, 2017, 5:38am UTC](https://discuss.elastic.co/t/how-to-refer-path-from-filter-to-other/1698/7 "2017-07-06T05:38:44Z")

</div>


