# Using Upsert across index

**URL:** <https://discuss.elastic.co/t/using-upsert-across-index/214465>\
**Category:** Logstash\
**Created:** [January 9, 2020, 4:30pm UTC](https://discuss.elastic.co/t/using-upsert-across-index/214465 "2020-01-09T16:30:26Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![smo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smo/32/44739_2.png) [@smo](https://discuss.elastic.co/u/smo)\
**Post date:** [January 9, 2020, 4:30pm UTC](https://discuss.elastic.co/t/using-upsert-across-index/214465/1 "2020-01-09T16:30:27Z")

</div>

I use this config to insert document in ES :```  
output {  
if [type] == "usage" {  
elasticsearch {  
hosts =\> ["elastic4:9204"]  
index =\> "usage-%{+YYYY-MM}"  
document\_id =\> "%{IDSU}"  
action =\> "update"  
doc\_as\_upsert =\> true  
}

```
    }

```

This is fine but the problem i have the duplicates occur within the different month, when the month rolls over, and the document still appears, elastic/logstash thinks it's a new doc, and create new document bu i want to do is to update document wich dos'ent exist in current index but in the old index.

Is there a way to make the upsert work cross index? These would all be the same type of doc, they would simply apply change status field for exampl

---

<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:** [January 9, 2020, 4:59pm UTC](https://discuss.elastic.co/t/using-upsert-across-index/214465/2 "2020-01-09T16:59:51Z")

</div>

I cannot think of any way to have an update to one index be redirected to a different index depending on the contents of the second index.

---

<div class="post-metadata">

**Author:** ![smo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smo/32/44739_2.png) [@smo](https://discuss.elastic.co/u/smo)\
**Post date:** [January 9, 2020, 5:15pm UTC](https://discuss.elastic.co/t/using-upsert-across-index/214465/3 "2020-01-09T17:15:26Z")

</div>

But the indexs have the same structure juste , i create every month new index , what i want when i want add doc i must search in old index if the same doc with doc\_id already exist if this case i update in the document in old index, else i creat one new document in the last index index (of current month) , i use upsert it work fine if this is the same index but i if not i have duplicate document

---

<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:** [January 9, 2020, 5:19pm UTC](https://discuss.elastic.co/t/using-upsert-across-index/214465/4 "2020-01-09T17:19:38Z")

</div>

> [@sbenk](#):
>
> i use upsert it work fine if this is the same index

Exactly. It works in the same index but not across indexes. That's working as expected.

---

<div class="post-metadata">

**Author:** ![smo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smo/32/44739_2.png) [@smo](https://discuss.elastic.co/u/smo)\
**Post date:** [January 9, 2020, 5:22pm UTC](https://discuss.elastic.co/t/using-upsert-across-index/214465/5 "2020-01-09T17:22:27Z")

</div>

Thank you so much , so there is no way to check document accos index befor insert , using elastic search output plugin ?

---

<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:** [February 6, 2020, 5:22pm UTC](https://discuss.elastic.co/t/using-upsert-across-index/214465/6 "2020-02-06T17:22:35Z")

</div>

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