# How to use script upsert in logstash for updating document

**URL:** <https://discuss.elastic.co/t/how-to-use-script-upsert-in-logstash-for-updating-document/172588>\
**Category:** Logstash\
**Created:** [March 15, 2019, 5:35pm UTC](https://discuss.elastic.co/t/how-to-use-script-upsert-in-logstash-for-updating-document/172588 "2019-03-15T17:35:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raunak\_Kumar](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raunak_kumar/32/42132_2.png) [@Raunak\_Kumar](https://discuss.elastic.co/u/Raunak_Kumar)\
**Post date:** [March 15, 2019, 5:35pm UTC](https://discuss.elastic.co/t/how-to-use-script-upsert-in-logstash-for-updating-document/172588/1 "2019-03-15T17:35:18Z")

</div>

I am using below output block to upsert the document and incrementing the counter (partial updates) for an existing document with matching ID.

Currently, post first doc entry into elasticsearch , "script" has not impact through the subsequent update calls. It is not incrementing the counter value

Below is the output block of logstash using upsert and script:

```auto
`output {
    stdout { }
    elasticsearch {
    hosts => "localhost"
    index => "test_dest"
    script => "ctx._source.views+=1"
    script_lang => "painless"
    script_type => "inline"
    # scripted_upsert => true 
    doc_as_upsert => true
    document_id => "%{[userId]}"
  }
  stdout {
    codec => "json"
  }
}`

```

---

<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 12, 2019, 5:35pm UTC](https://discuss.elastic.co/t/how-to-use-script-upsert-in-logstash-for-updating-document/172588/2 "2019-04-12T17:35:19Z")

</div>

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