# Illegal State Exception while adding watcher to ES 5.1.2 using X-Pack

**URL:** <https://discuss.elastic.co/t/illegal-state-exception-while-adding-watcher-to-es-5-1-2-using-x-pack/74847>\
**Category:** Elasticsearch\
**Created:** [February 13, 2017, 7:59am UTC](https://discuss.elastic.co/t/illegal-state-exception-while-adding-watcher-to-es-5-1-2-using-x-pack/74847 "2017-02-13T07:59:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Prateek\_Sharma](https://avatars.discourse-cdn.com/v4/letter/p/e56c9b/32.png) [@Prateek\_Sharma](https://discuss.elastic.co/u/Prateek_Sharma)\
**Post date:** [February 13, 2017, 7:59am UTC](https://discuss.elastic.co/t/illegal-state-exception-while-adding-watcher-to-es-5-1-2-using-x-pack/74847/1 "2017-02-13T07:59:46Z")

</div>

Hi,

I have been trying to add a watcher on ES 5.1.2 using X-pack. I am getting **IllegalStateException** while using this payload for PUT \_xpack/watcher/watch/first\_watcher:

{  
"trigger": {  
"schedule": {  
"interval": "10s"  
}  
},  
"input": {  
"search": {  
"request": {  
"indices": ["logstash-\*"],  
"body": {  
"query": {  
"bool": {  
"must": [{  
"match": {  
"actionType": "SOME\_ACTION\_TYPE"  
}  
}, {  
"range": {  
"@timestamp": {  
"gte": "now-1d",  
"lt": "now"  
}  
}  
}]  
}  
}  
}  
}  
}  
},  
"condition": {  
"compare": {  
"ctx.payload.hits.total": {  
"gt": 0  
}  
}  
},  
"actions": {  
"send\_email": {  
"email": {  
"to": "user@account.com",  
"subject": "Notification Details",  
"body": "Result: \n Notifications Sent: {{ctx.payload.hits.hits[0].sentCount}}, \n Time Taken: {{ctx.payload.hits.hits[0].timeTaken}}"  
}  
}  
}  
}

Excetion on elastic search logs:

[2017-02-13T07:47:36,598][WARN][r.suppressed] path: /\_xpack/watcher/watch/first\_watcher, params: {id=first\_watcher}  
java.lang.IllegalStateException: not started  
at org.elasticsearch.xpack.watcher.WatcherService.ensureStarted(WatcherService.java:251) ~[x-pack-5.1.2.jar:5.1.2]  
at org.elasticsearch.xpack.watcher.WatcherService.putWatch(WatcherService.java:132) ~[x-pack-5.1.2.jar:5.1.2]  
at org.elasticsearch.xpack.watcher.transport.actions.put.TransportPutWatchAction.masterOperation(TransportPutWatchAction.java:76) [x-pack-5.1.2.jar:5.1.2]  
at org.elasticsearch.xpack.watcher.transport.actions.put.TransportPutWatchAction.masterOperation(TransportPutWatchAction.java:43) [x-pack-5.1.2.jar:5.1.2]  
at org.elasticsearch.action.support.master.TransportMasterNodeAction.masterOperation(TransportMasterNodeAction.java:86) [elasticsearch-5.1.2.jar:5.1.2]  
at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction$3.doRun(TransportMasterNodeAction.java:170) [elasticsearch-5.1.2.jar:5.1.2]  
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:527) [elasticsearch-5.1.2.jar:5.1.2]  
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37) [elasticsearch-5.1.2.jar:5.1.2]  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [?:1.8.0\_121]  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [?:1.8.0\_121]  
at java.lang.Thread.run(Thread.java:745) [?:1.8.0\_121]

Response:

{  
"error": {  
"root\_cause": [{  
"type": "illegal\_state\_exception",  
"reason": "not started"  
}],  
"type": "illegal\_state\_exception",  
"reason": "not started"  
},  
"status": 500  
}

I have tried reindexing also, but still I am getting the same error.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [February 15, 2017, 10:50am UTC](https://discuss.elastic.co/t/illegal-state-exception-while-adding-watcher-to-es-5-1-2-using-x-pack/74847/2 "2017-02-15T10:50:42Z")

</div>

Hey,

have you made sure that watcher is start? You can start watcher using the [start API](https://www.elastic.co/guide/en/x-pack/5.2/watcher-api-start.html).

However there might be a reason why starting does not work - maybe one of the required shards is not ready or closed. Can you run this as well

```auto
GET _cat/indices/.watch*,.triggered*?v

```

Thanks.

--Alex

---

<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:** [March 15, 2017, 10:50am UTC](https://discuss.elastic.co/t/illegal-state-exception-while-adding-watcher-to-es-5-1-2-using-x-pack/74847/3 "2017-03-15T10:50:44Z")

</div>

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