# How do I add a new field based on the contents of a file?

**URL:** <https://discuss.elastic.co/t/how-do-i-add-a-new-field-based-on-the-contents-of-a-file/243340>\
**Category:** Logstash\
**Created:** [July 31, 2020, 11:08am UTC](https://discuss.elastic.co/t/how-do-i-add-a-new-field-based-on-the-contents-of-a-file/243340 "2020-07-31T11:08:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![blueren](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@blueren](https://discuss.elastic.co/u/blueren)\
**Post date:** [July 31, 2020, 11:08am UTC](https://discuss.elastic.co/t/how-do-i-add-a-new-field-based-on-the-contents-of-a-file/243340/1 "2020-07-31T11:08:28Z")

</div>

Hi,

I'm currently using the netflow codec to decode netflow data and store in elastic. I want to introduce a new field called "site\_id". The site ID is going to be present in a file called `/tmp/site.id` This file will contain just one line and will be a number

eg:\>

```
cat /tmp/site.id
12345678

```

How do I add this field to every even that is being processed by logstash?

Eg\>

```
 mutate {
        id => "site"
        add_field => {
            "[flow][violation]" => "false"
            "[flow][threat]" => "false"
            "[flow][site_id]" => //=======> read file /tmp/site.id and assign value 

        }
    }
```

---

<div class="post-metadata">

**Author:** ![egray](https://avatars.discourse-cdn.com/v4/letter/e/278dde/32.png) [@egray](https://discuss.elastic.co/u/egray)\
**Post date:** [July 31, 2020, 11:14am UTC](https://discuss.elastic.co/t/how-do-i-add-a-new-field-based-on-the-contents-of-a-file/243340/2 "2020-07-31T11:14:38Z")

</div>

You may be able to use the Ruby filter plugin and write a Ruby script, so long as file handling is enabled. I haven't tested this myself.  
[Ruby filter plugin](https://www.elastic.co/guide/en/logstash/current/plugins-filters-ruby.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:** [August 28, 2020, 11:14am UTC](https://discuss.elastic.co/t/how-do-i-add-a-new-field-based-on-the-contents-of-a-file/243340/3 "2020-08-28T11:14:38Z")

</div>

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