# Create dictionary file using logstash file output

**URL:** <https://discuss.elastic.co/t/create-dictionary-file-using-logstash-file-output/157661>\
**Category:** Logstash\
**Created:** [November 21, 2018, 9:22am UTC](https://discuss.elastic.co/t/create-dictionary-file-using-logstash-file-output/157661 "2018-11-21T09:22:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![serhii.zaidlin](https://avatars.discourse-cdn.com/v4/letter/s/b77776/32.png) [@serhii.zaidlin](https://discuss.elastic.co/u/serhii.zaidlin)\
**Post date:** [November 21, 2018, 9:22am UTC](https://discuss.elastic.co/t/create-dictionary-file-using-logstash-file-output/157661/1 "2018-11-21T09:22:09Z")

</div>

Hi everyone.  
I have a scheduled input which pulls API and recieves batch of device details and refreshes device info in Elastcisearch index (so if I have 100 devices, i will always have 100 docs in elastic index). This input includes "device\_id" and "device\_hostname" fields.  
I need to make dictionary for translate filter from this values, in form: "device\_id: device\_hostname".  
My output looks like this;

> ```
> output {
> file {
> path => "/tmp/dict_hosts"
> codec => line { format => "%{device_id} : %{device_hostname}"} 
> } 
> }
> 
> ```

The problem is that every time output executes it adds the same 100 "device\_id: device\_hostname" pairs to the end of file and it grows. If I use "write\_behavior =\> overwrite" than I get only one line in dictionary.  
Is there a way to overwrite file once per batch write?

---

<div class="post-metadata">

**Author:** ![faulander](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/faulander/32/36344_2.png) [@faulander](https://discuss.elastic.co/u/faulander)\
**Post date:** [November 21, 2018, 10:31am UTC](https://discuss.elastic.co/t/create-dictionary-file-using-logstash-file-output/157661/2 "2018-11-21T10:31:17Z")

</div>

Since you only have two options for the file output which you already tried, i would create a small batch or python script which deletes the file before writing to it from logstash.

Maybe this link gets you going:

> **[How to incorporate external utility scripts into Logstash Pipeline](http://vrepin.org/vr/Logstash-filter-external-script/)**
>
> This article describes the approach to call external applications from Logstash Pipeline and use their (JSON/XML/key-value) output in the further filtering process.

---

<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:** [December 19, 2018, 10:31am UTC](https://discuss.elastic.co/t/create-dictionary-file-using-logstash-file-output/157661/3 "2018-12-19T10:31:20Z")

</div>

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