Conditional action only if list exists

alerting

(Steve Stevens) #1

I have a watcher that performs a transform on matched records and then posts the result into a different index. I am making use of "ctx.payload._doc" to insert into the index. Depending on a complex action in the transform there is the potential to have an empty _doc list come back out. I'm not sure how to write the action condition to stop it trying to index nothing as it seems to "fail" on receiving the empty set.

Is it possibly to create a "total" field via a transform to perform the conditional against or would that interfere with the index actions mechanism to autoindex the list?

"condition":{
    "compare":{
      "ctx.payload.hits.total":{
        "gt":0
      }
    }
  },
  "transform":{
    "script":{
      "inline":"return ['_doc': []]",
      "lang": "painless"
    }
  },
  "actions":{
    "condition": {
          ??????
      }
    },
    "index_payload":{
      "index":{
        "index":"hazelcast",
        "doc_type":"hazelcast"
      }
    }
  }

(Alexander Reelsen) #2

have you tried something like ctx.payload._doc.size() > 0


(Steve Stevens) #3

as painless?! I don't know why I didn't think of doing that...
placed condition within index_payload and it worked beautifully. Thanks!

"actions": {
"index_payload": {
"condition":{
"script":{
"source":"return ctx.payload._doc.size() > 0;",
"lang":"painless"
}
},
"index": {
"index": "hazelcast",
"doc_type": "hazelcast"
}
}
}


(system) #4

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