Created
November 7, 2023 09:51
-
-
Save fbaligand/8b69be0323e8fb10b4d8c38626c0e63d to your computer and use it in GitHub Desktop.
Chain Watcher with array injection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PUT _watcher/watch/my_chain_watch | |
{ | |
"trigger": { | |
"schedule": { | |
"interval": "30m" | |
} | |
}, | |
"input": { | |
"chain": { | |
"inputs": [ | |
{ | |
"first": { | |
"simple": { | |
"my_array": [ | |
"JP", | |
"FR" | |
] | |
} | |
} | |
}, | |
{ | |
"second": { | |
"search": { | |
"request": { | |
"search_type": "query_then_fetch", | |
"indices": [ | |
"kibana_sample_data_flights" | |
], | |
"rest_total_hits_as_int": true, | |
"template": { | |
"source": """{ | |
"size": 0, | |
"query": { | |
"terms": { | |
"DestCountry": {{#toJson}}ctx.payload.first.my_array{{/toJson}} | |
} | |
} | |
}""", | |
"lang": "mustache" | |
} | |
} | |
} | |
} | |
} | |
] | |
} | |
}, | |
"condition": { | |
"compare": { | |
"ctx.payload.second.hits.total": { | |
"gte": 0 | |
} | |
} | |
}, | |
"actions": { | |
"my-logging-action": { | |
"logging": { | |
"level": "info", | |
"text": "There are {{ctx.payload.second.hits.total}} documents in your index. Threshold is 10." | |
} | |
} | |
}, | |
"metadata": { | |
"xpack": { | |
"type": "json" | |
}, | |
"name": "my_chain_watch" | |
} | |
} | |
POST /_watcher/watch/my_chain_watch/_execute | |
{ | |
"trigger_data" : { | |
"triggered_time" : "now", | |
"scheduled_time" : "now" | |
}, | |
"record_execution" : true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment