# Does First Input First Output in logstash

**URL:** <https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850>\
**Category:** Logstash\
**Created:** [November 16, 2017, 2:22am UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850 "2017-11-16T02:22:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![lsyoung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lsyoung/32/90815_2.png) [@lsyoung](https://discuss.elastic.co/u/lsyoung)\
**Post date:** [November 16, 2017, 2:22am UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850/1 "2017-11-16T02:22:15Z")

</div>

Can logstash ensure the message first read by input-plugin can be output firstly with output-plugin?  
AND  
If if the output-plugin is elasticsearch, does the the docs write into elasticsearch by the same sequence with the input-plugin read?  
BECAUSE,  
I want to update the previous data with the data behind.  
Anyone can help, Thanks!!!

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [November 16, 2017, 9:20am UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850/2 "2017-11-16T09:20:22Z")

</div>

The worker threads can arrive at an output in any order because the any thread can be delayed relative to the other.

For strict in-order processing you need to have only 1 worker thread. Setting `pipeline.workers`.  
For version 5.6 read [https://www.elastic.co/guide/en/logstash/5.6/logstash-settings-file.html](https://www.elastic.co/guide/en/logstash/5.6/logstash-settings-file.html)  
For version 6.0 read [https://www.elastic.co/guide/en/logstash/6.0/logstash-settings-file.html](https://www.elastic.co/guide/en/logstash/6.0/logstash-settings-file.html)

**HOWEVER** If you are trying to overwrite earlier documents with later documents based on some identifier value then you need a different strategy.

If you are looking for a kind of upsert, replace, overwrite or merge type action please say so, we can then help further.

---

<div class="post-metadata">

**Author:** ![lsyoung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lsyoung/32/90815_2.png) [@lsyoung](https://discuss.elastic.co/u/lsyoung)\
**Post date:** [November 16, 2017, 10:07am UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850/3 "2017-11-16T10:07:50Z")

</div>

Thanks!

YES, I want to delete the earlier document, any good advice? Tanks!!!  
When the `field1` is `"0"` I index a document, then when document with the same value of `field2` comes and `field1 != "0"` , I want to delete the document created before.  
I use this configure now:

```
input{}
filter{
    if [field1] == "0"{
        mutate{
            add_field =>{
                "[@metadata][action]" => "index"
            }
        }
    }else {
        mutate{
            add_field =>{
                "[@metadata][action]" => "delete"
            }
        }
		}
}
output{
    elasticsearch { 
			hosts => ["XXXX"]
			index => "XXXX"
			document_id => "%{field2}"
			action => "%{[@metadata][action]}"
			document_type => "%{type}"
			flush_size => 300
			idle_flush_time => 10
			sniffing => false
			codec => "json"
		}
}
```

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [November 16, 2017, 1:09pm UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850/4 "2017-11-16T13:09:08Z")

</div>

This [link](https://www.elastic.co/guide/en/elasticsearch/reference/5.6/_modifying_your_data.html#_indexing_replacing_documents) shows that you can use the document\_id to overwrite the previous doc with the index action.

However, you have some logic to implement and a consideration of timing, I think.

I'm confused. Your first post says that you want to update older docs but your newer post seems to say this:  
Documents will only remain in the index if no other docs having the same id AND field1 != 0 are ingested.

---

<div class="post-metadata">

**Author:** ![lsyoung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lsyoung/32/90815_2.png) [@lsyoung](https://discuss.elastic.co/u/lsyoung)\
**Post date:** [November 16, 2017, 1:58pm UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850/5 "2017-11-16T13:58:53Z")

</div>

> [@guyboertje](#):
>
> Documents will only remain in the index if no other docs having the same id AND field1 != 0 are ingested.

That is my goal. In my first post, I when I say `update the data` I mean delete it, sorry for not saying clearly.  
So, if I want to use logstash to achieve my goal, setting `pipeline.workers` to 1 will help.  
I will try it.  
Thanks for patiently answering my question!

---

<div class="post-metadata">

**Author:** ![guyboertje](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/guyboertje/32/31592_2.png) [@guyboertje](https://discuss.elastic.co/u/guyboertje)\
**Post date:** [November 16, 2017, 2:58pm UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850/6 "2017-11-16T14:58:03Z")

</div>

> [@lsyoung](#):
>
> document\_id =\> "%{filed2}"

Good luck! make sure you have the correct spelling in `document_id` setting.

---

<div class="post-metadata">

**Author:** ![lsyoung](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lsyoung/32/90815_2.png) [@lsyoung](https://discuss.elastic.co/u/lsyoung)\
**Post date:** [November 17, 2017, 3:23am UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850/7 "2017-11-17T03:23:56Z")

</div>

`field2` is not what I actually used, it's a an example. Anyway, thank you for your reminder,  
I will correct it.

---

<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 15, 2017, 3:24am UTC](https://discuss.elastic.co/t/does-first-input-first-output-in-logstash/107850/8 "2017-12-15T03:24:40Z")

</div>

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