0

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:

  `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"
  }
}`
user3784024
  • 11
  • 1
  • 3

1 Answers1

0

Try to set the action to "update" and scripted_upsert to "true" as below:

output {
    elasticsearch {
       action => "update"
       hosts => "localhost"
       index => "test_dest"
       script => "ctx._source.views+=1"
       script_lang => "painless"
       script_type => "inline"
       scripted_upsert => true 
       document_id => "%{[userId]}"
     }
}
Kate Orlova
  • 3,225
  • 5
  • 11
  • 35
Peter
  • 1
  • 1