I have following basic watcher.
{
"trigger": {
"schedule": {
"interval": "1m"
}
},
"input": {
"chain": {
"inputs": [
{
"first_input": {
"http": {
"request": {
"url": "http://example.com/first_input",
"params": {},
"headers": {}
}
}
}
},
{
"second_input": {
"http": {
"request": {
"url": "http://example.com/second_input",
"params": {},
"headers": {}
}
}
}
}
]
}
},
"condition": {
"script": {
"source": "for (def item : ctx.payload.first_input) { if (item.some_field > 10) { return true; } } return false;",
"lang": "painless"
}
},
"actions": {
"send_email": {
"email": {
"to": "email@example.com",
"subject": "Watcher Triggered",
"body": {
"text": "The watcher was triggered."
}
}
}
}
}
I want to run second_input in foreach for the total count of first_input.
So i changed the code like this for second_input
second_input": {
"foreach": "ctx.payload.first_input.hits.hits",
"max_iterations": 50,
"http": {
"request": {
"url": "http://example.com/second_input",
"params": {},
"headers": {}
}
}
}
As soon i try to save it i get this error.
could not parse input for watch [chain_example]. expected an object representing input [foreach], but found [VALUE_STRING] instead
But if i remove that for each code and print in log following it , it shows total count.
Total {{ctx.payload.first_input.hits.total}} shows # i.e 12
How can i fix this ?