Scripted upsert issues

I am currently trying to do calculations based on correlating field values from different documents and decided achieve this by using scripted_upsert method to update and create the documents based on the document id but for some reason the new documents are not getting generated Here's my conig.

output {
  elasticsearch {
    index                        => "%{metric_type}_alias"
    user                         => "user"
    password                     => "password"
    hosts                        => ["https://xxx.xxx.xx.xx:9200"]
    ssl                          => true
    ssl_certificate_verification => true
    cacert                       => '/path/to/cacert'
    keystore                     => 'path/to/keystore'
    keystore_password            => "password}"
  }
  if [metric_type] == "tx_metric" {
   stdout { codec => rubydebug }
   elasticsearch {
      action                       => "update"
      index                        => "tx_calculated_alias"
      user                         => "user"
      password                     => "password"
      hosts                        => ["https://xxx.xxx.xx.xx:9200"]
      ssl                          => true
      ssl_certificate_verification => true
      cacert                       => '/path/to/cacert'
      keystore                     => '/path/to/keystore'
      keystore_password            => "password"
      document_id => "%{[tx_uuid]}"
      scripted_upsert => true
      script => '
        if ("create".equals(ctx.op)) {
          if (params.event.get("status") == "SUBMITTED") {
            ctx._source = [
              "tx_uuid": params.event.get("tx_uuid"),
              "submitted_time": params.event.get("status_time"),
              "uuid": params.event.get("uuid"),
              "metric_type": params.event.get("metric_type"),
              "source_server": params.event.get("server"),
              "metric_count": 1
            ]
          } else (params.event.get("status") == "COMPLETE") {
            ctx._source = [
              "tx_uuid": params.event.get("tx_uuid"),
              "completed_time": params.event.get("status_time"),
              "uuid": params.event.get("uuid"),
              "metric_type": params.event.get("metric_type"),
              "destination_server": params.event.get("server"),
              "metric_count": 1
            ]
          }
        } else {
           if (params.event.get("status") == "SUBMITTED") {
             ctx._source.source_server = params.event.get("server");
             ctx._source.submitted_time = params.event.get("status_time");
           } else (params.event.get("status") == "COMPLETE") {
             ctx._source.destination_server = params.event.get("server");
             ctx._source.completed_time = params.event.get("status_time");
           }

           if (ctx._source.containsKey("submitted_time")  && ctx._source.containsKey("completed_time")) {
             ctx._source.tx_duration = ctx._source.completed_time - ctx._source.submitted_time;
           }
        }
      '
    }
  }
}

Not sure what the issue is here

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