# Debuging a watcher

**URL:** <https://discuss.elastic.co/t/debuging-a-watcher/262138>\
**Category:** Elasticsearch\
**Created:** [January 25, 2021, 4:23pm UTC](https://discuss.elastic.co/t/debuging-a-watcher/262138 "2021-01-25T16:23:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bastien\_SANDER](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bastien_sander/32/78592_2.png) [@Bastien\_SANDER](https://discuss.elastic.co/u/Bastien_SANDER)\
**Post date:** [January 25, 2021, 4:23pm UTC](https://discuss.elastic.co/t/debuging-a-watcher/262138/1 "2021-01-25T16:23:31Z")

</div>

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 :

```auto
    {
    	"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:

```auto
        {
        "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
    }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 22, 2021, 4:23pm UTC](https://discuss.elastic.co/t/debuging-a-watcher/262138/2 "2021-02-22T16:23:31Z")

</div>

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