# Add field if the input file comes from a certain path

**URL:** <https://discuss.elastic.co/t/add-field-if-the-input-file-comes-from-a-certain-path/218859>\
**Category:** Logstash\
**Created:** [February 11, 2020, 8:20pm UTC](https://discuss.elastic.co/t/add-field-if-the-input-file-comes-from-a-certain-path/218859 "2020-02-11T20:20:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Incauto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/incauto/32/60149_2.png) [@Incauto](https://discuss.elastic.co/u/Incauto)\
**Post date:** [February 11, 2020, 8:20pm UTC](https://discuss.elastic.co/t/add-field-if-the-input-file-comes-from-a-certain-path/218859/1 "2020-02-11T20:20:09Z")

</div>

Hi I want to add a field depending on the path of the input log file, something like this:

```auto
input {
        file {
                path => "some_path/uptime*"
                path => "some_other_path/uptime*"
                
                if path == "/u01/some_path/uptime*"
                            add_field => {"server" => "some_server" }
                
                if path == "/u01/some_other_path/uptime*"
                            add_field => {"server" => "some_other_server" }

                add_field => {"application" => "uptime" } #this is not part of the conditional
        }
}

filter {
        if [application] == "uptime" {
                grok { .............................

```

how can I do this?

---

<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 11, 2020, 9:16pm UTC](https://discuss.elastic.co/t/add-field-if-the-input-file-comes-from-a-certain-path/218859/2 "2020-02-11T21:16:20Z")

</div>

Use two file inputs.

---

<div class="post-metadata">

**Author:** ![Incauto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/incauto/32/60149_2.png) [@Incauto](https://discuss.elastic.co/u/Incauto)\
**Post date:** [February 12, 2020, 12:39am UTC](https://discuss.elastic.co/t/add-field-if-the-input-file-comes-from-a-certain-path/218859/3 "2020-02-12T00:39:36Z")

</div>

Thanks again badger, something like this? sorry to bother you again badger but right know i dont have acces to logstash, and tomorrow I have to do this in the least time posible.

```auto
input {
        file {
                path => "some_path/uptime*"                
                add_field => {"server" => "some_server" }

                add_field => {"application" => "uptime" } #this is not part of the conditional
        }
        file {
                path => "some_other_path/uptime*"
                add_field => {"server" => "some_other_server" }

                add_field => {"application" => "uptime" } #this is not part of the conditional
        }
}

filter {
        if [application] == "uptime" {
                grok {...}
        }
}
output{
         if [application] == "uptime" {
                elasticsearch {
                       hosts => ["elastic:9200"]
                       index => "uptime-%{+YYYY.MM.dd}"
               }
        }
}
```

---

<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 12, 2020, 1:46am UTC](https://discuss.elastic.co/t/add-field-if-the-input-file-comes-from-a-certain-path/218859/4 "2020-02-12T01:46:20Z")

</div>

That looks like it would work, but I am unclear why you would make everything conditional when they all appear to satisfy the same condition. Adding tags and testing for the tags being there appears to be a no-op.

---

<div class="post-metadata">

**Author:** ![Incauto](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/incauto/32/60149_2.png) [@Incauto](https://discuss.elastic.co/u/Incauto)\
**Post date:** [February 12, 2020, 2:44am UTC](https://discuss.elastic.co/t/add-field-if-the-input-file-comes-from-a-certain-path/218859/5 "2020-02-12T02:44:14Z")

</div>

Do you mean the "if [application] == "uptime"" on the filter and the ouput?

the person that was working before me in logstash didnt use pipelines.yml to run multiples pipelines, use another method, I think he ran multiples pipelines on one .conf, so to avoid data mixing he use the conditionals, I picked up the same practice by ignorance I think, and because I use the "application" field when I do requests in the elastic api, but you are right, im gonna get rid of the conditionals and simply add the field....Thanks again Badger, as always you are very helpful.

---

<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 11, 2020, 2:44am UTC](https://discuss.elastic.co/t/add-field-if-the-input-file-comes-from-a-certain-path/218859/6 "2020-03-11T02:44:24Z")

</div>

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