How to hand over a value from my Watcher request to my Watcher action (Webhook)?

Hello,

I'm trying to hand over an ID from my Watcher context/request to my Watcher action (Webhook).

There are the following Fields:

workerId.keyword = string
f1score = number
assignment_completed = boolean

If a workerId have an average f1Score < 0.7 I want to hand over the workerId to the body of my Action.

"WorkerId": here the workerId.keyword of the one with average f1Score < 0.7 should appear

Here you can see my actual request:
(I am asking actualy for a workerId.keyword in the last 5 min with an avg f1score < 0.7 )

{
  "trigger": {
    "schedule": {
      "interval": "30s"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "mobots_assignments*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query": {
            "bool": {
              "filter": {
                "range": {
                  "start_time": {
                    "gte": "{{ctx.trigger.scheduled_time}}||-5m",  
                    "lte": "{{ctx.trigger.scheduled_time}}",
                    "format": "strict_date_optional_time||epoch_millis"
                  }
                }
              }
            }
          },
          "aggs": {
            "bucketAgg": {
              "terms": {
                "field": "workerId.keyword",
                "size": 1,
                "order": {
                  "metricAgg": "asc"
                }
              },
              "aggs": {
                "metricAgg": {
                  "min": {
                    "field": "f1score"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "script": {
      "source": "ArrayList arr = ctx.payload.aggregations.bucketAgg.buckets; for (int i = 0; i < arr.length; i++) { if (arr[i]['metricAgg'].value < params.threshold) { return true; } } return false;",
      "lang": "painless",
      "params": {
        "threshold": 0.7
      }
    }
  },
  "actions": {
    "mobots_webhook": {
      "webhook": {
        "scheme": "https",
        "host": "www.xyz.com",
        "port": 443,
        "method": "post",
        "path": "/worker_block",
        "params": {},
        "headers": {
          "Host": "www.xyz.com",
          "Content-Type": "application/json"
        },
        "body": {
          "source": {
            "WorkerId": "HERE THE workerId.keyword OF THE ONE WITH AVERAGE F1SCORE<0.7 SHOULD APPEAR",
            "Reason": "for test"
          },
          "lang": "mustache",
          "options": {
            "content_type": "application/json; charset=UTF-8"
          }
        }
      }
    }
  }
}

If you need more Information, let me know.
Thank you for reading.

Hello,
I'm following your question correctly, I think you should be able to access it through ctx.payload

These docs may be helpful :
https://www.elastic.co/guide/en/x-pack/current/how-watcher-works.html#templates

https://www.elastic.co/guide/en/elasticsearch/painless/master/painless-watcher-condition-context.html

Let us know if this helps, else we can dig more.

Thanks
Rashmi

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