I want to update all document of a collection, and setting a boolean to false if the documents are returned by a query.
I would like to create the following watcher :
{
"trigger": {
"schedule": {
"daily": {
"at": [
"08:00"
]
}
}
},
"input": {
"search": {
"request": {
"indices": [
"sensors"
],
"body": {
"query": {
"range": {
"lastPeriodicalMeasure.date": {
"lte": "now-1d/d"
}
},
"term": {
"isActive": true
}
}
}
}
}
},
"condition": {
"always": {}
},
"actions": {
"index_payload": {
"transform": {
"script": """
def documents = ctx.payload.hits.hits.stream();
for (int i = 0; i < documents.length; ++i) {
documents[i].isActive = false
}
return ["_doc": documents];
"""
},
"index": {}
}
}
}
I followed step by step the documentation, and I don't get why the API reject my script.
I get the following error:
{
"error": {
"root_cause": [
{
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"",
"^---- HERE"
],
"script": "",
"lang": "painless",
"position": {
"offset": 0,
"start": 0,
"end": 0
}
}
],
"type": "script_exception",
"reason": "compile error",
"script_stack": [
"",
"^---- HERE"
],
"script": "",
"lang": "painless",
"position": {
"offset": 0,
"start": 0,
"end": 0
},
"caused_by": {
"type": "illegal_argument_exception",
"reason": "Cannot generate an empty script."
}
},
"status": 400
}