# Multiple output to same elasticsearch in order, one for delete action, another for normal action(create if)

**URL:** <https://discuss.elastic.co/t/multiple-output-to-same-elasticsearch-in-order-one-for-delete-action-another-for-normal-action-create-if/125691>\
**Category:** Logstash\
**Created:** [March 27, 2018, 3:11am UTC](https://discuss.elastic.co/t/multiple-output-to-same-elasticsearch-in-order-one-for-delete-action-another-for-normal-action-create-if/125691 "2018-03-27T03:11:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jin\_Qian](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jin\_Qian](https://discuss.elastic.co/u/Jin_Qian)\
**Post date:** [March 27, 2018, 3:11am UTC](https://discuss.elastic.co/t/multiple-output-to-same-elasticsearch-in-order-one-for-delete-action-another-for-normal-action-create-if/125691/1 "2018-03-27T03:11:25Z")

</div>

See detail in [https://stackoverflow.com/questions/49441683/logstash-elasticsearch-how-can-i-remove-all-data-before-output-new-data](https://stackoverflow.com/questions/49441683/logstash-elasticsearch-how-can-i-remove-all-data-before-output-new-data)

I just want to delete old data before output new data.

So I am curious, if I define two outputs to same elasticsearch, one for delete action, another for normal action, what will happen? Can logstash ensure to run output in order?

```
output {
  elasticsearch {
    hosts => ["docker.for.mac.localhost:19200"]
    index => "osquery-%{host}"
    action => "delete"
  }
  elasticsearch {
    hosts => ["docker.for.mac.localhost:19200"]
    index => "osquery-%{host}"
  }
}

```

EDIT@2018-03-28

I'v solved this issue [https://stackoverflow.com/a/49504227/2293666](https://stackoverflow.com/a/49504227/2293666), so no need to talk about this topic.

Logstash seems run output in parallel, not possible to output one by one in order defined in the conf.

---

<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:** [March 27, 2018, 6:30pm UTC](https://discuss.elastic.co/t/multiple-output-to-same-elasticsearch-in-order-one-for-delete-action-another-for-normal-action-create-if/125691/2 "2018-03-27T18:30:24Z")

</div>

Why can't you just update the existing document? I don't see the point in deleting and recreating it.

---

<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:** [March 27, 2018, 6:40pm UTC](https://discuss.elastic.co/t/multiple-output-to-same-elasticsearch-in-order-one-for-delete-action-another-for-normal-action-create-if/125691/3 "2018-03-27T18:40:27Z")

</div>

If you want to have one document for each host+package, then set the document\_id to be a function (possibly the concatetation of) host+package. Then it will keep overwriting the documents each time you get a new set of data.

---

<div class="post-metadata">

**Author:** ![Jin\_Qian](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jin\_Qian](https://discuss.elastic.co/u/Jin_Qian)\
**Post date:** [March 28, 2018, 1:25am UTC](https://discuss.elastic.co/t/multiple-output-to-same-elasticsearch-in-order-one-for-delete-action-another-for-normal-action-create-if/125691/4 "2018-03-28T01:25:19Z")

</div>

Actually at first I tried to overwrite existing document. But soon I found the problem is that the output is multiple documents, not a single document, sometimes more, sometime less, so it is not a simple update. It must be a remove all & add.

And the object inside array is not a fixed schema,  
I can not assume which field is key,  
and to be able to search inside array precisely,  
I need to split array into multiple documents(events) instead of specify snapshot as "nested" object in elasticsearch mapping.

Someday:  
{packages: [{name:"pkg1", version:"1"}, {name:"pkg2", version:"2"}]}  
{...: [{...}, {...}]}

Another day:  
{mounts: [{path:"path1", device:"dev1"}, {path:"path2", device:"dev2"]}  
{...: [{...}, {...}]}

Another day:  
{modules: [{name:"mod1", desc:"desc1"}, {name:"mod1", desc:"desc1"]}  
{...: [{...}, {...}]}

Another day:  
{packages: [{name:"pkg1", version:"1"}, {name:"pkg2", version:"2"}, {name:"pkg3", version:"3"}]}  
{...: [{...}, {...}]}

---

<div class="post-metadata">

**Author:** ![Jin\_Qian](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jin\_Qian](https://discuss.elastic.co/u/Jin_Qian)\
**Post date:** [March 28, 2018, 1:30am UTC](https://discuss.elastic.co/t/multiple-output-to-same-elasticsearch-in-order-one-for-delete-action-another-for-normal-action-create-if/125691/5 "2018-03-28T01:30:14Z")

</div>

Thank you. Actually at first I tried to overwrite existing document. But soon I found the problem is that the output is multiple documents, not a single document, sometimes more, sometime less, so it is not a simple update. It must be a remove all & add. And the object inside array is not a fixed schema,  
I can not assume which field is key.

---

<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:** [April 25, 2018, 1:30am UTC](https://discuss.elastic.co/t/multiple-output-to-same-elasticsearch-in-order-one-for-delete-action-another-for-normal-action-create-if/125691/6 "2018-04-25T01:30:38Z")

</div>

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