# Implementing elasticsearch(1.0x) watcher using Java

**URL:** <https://discuss.elastic.co/t/implementing-elasticsearch-1-0x-watcher-using-java/117880>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [January 31, 2018, 7:24pm UTC](https://discuss.elastic.co/t/implementing-elasticsearch-1-0x-watcher-using-java/117880 "2018-01-31T19:24:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sumeet\_B](https://avatars.discourse-cdn.com/v4/letter/s/9fc29f/32.png) [@Sumeet\_B](https://discuss.elastic.co/u/Sumeet_B)\
**Post date:** [January 31, 2018, 7:24pm UTC](https://discuss.elastic.co/t/implementing-elasticsearch-1-0x-watcher-using-java/117880/1 "2018-01-31T19:24:33Z")

</div>

I am a novice in ES... I want to work with watcher of ES.  
Let's assume a scenario: Let's say I am a doctor. I have data about my patients in ES. Whenever the diagnostic team claims that the patient's health status is deteriorating I should be notified. As I am using Elasticsearch, I want to implement it using watcher in Java. I followed this [link](https://www.elastic.co/guide/en/watcher/watcher-1.0/api-java.html#_creating_the_watcherclient) but was not able to get a condition using Java. Also, the mustache template is confusing. Is it a good idea to write every logic in a script and access the same script in java class.

Can you please help me with it? If you have any better ideas please suggest which supports the above scenario.

Upon quering ES: [http://localhost:9200/clinic/\_search?pretty=1](http://localhost:9200/clinic/_search?pretty=1) , the response is as below:

> ```
> > {
> > "took": 1,
> > "timed_out": false,
> > "_shards": {
> > "total": 5,
> > "successful": 5,
> > "failed": 0
> > },
> > "hits": {
> > "total": 1,
> > "max_score": 1,
> > "hits": [{
> > "_index": "clinic",
> > "_type": "patients",
> > "_id": "AWEocy4uDyy-SYauj60G",
> > "_score": 1,
> > "_source": {
> > "Pdata": [{
> > "Status": "unhealthy",
> > "Name": "JohnDoe 1",
> > "disease": "Typhoid",
> > "Metrics": {
> > "BodyMetrics": [{
> > "symptoms": "fever",
> > "Type": "c"
> > }]
> > },
> > "Address": "abcd street",
> > "Date": 2412017,
> > "severity": "major"
> > },
> > {
> > "Status": "unhealthy",
> > "Name": "JohnDoe 2",
> > "disease": "Fatigue",
> > "Metrics": {
> > "BodyMetrics": [{
> > "symptoms": "weakness",
> > "Type": "a"
> > }]
> > },
> > "Address": "efgh street",
> > "Date": 22122017,
> > "severity": "minor"
> > },
> > {
> > "Status": "healthy",
> > "Name": "JohnDoe 3",
> > "disease": "HyperTension",
> > "Metrics": {
> > "BodyMetrics": [{
> > "symptoms": "tiredness",
> > "Type": "d"
> > }]
> > },
> > "Address": "xyz street",
> > "Date": 2412017,
> > "severity": "none"
> > }]
> > }
> > }]
> > }
> > }
> 
> ```

---

<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 7, 2018, 8:43am UTC](https://discuss.elastic.co/t/implementing-elasticsearch-1-0x-watcher-using-java/117880/2 "2018-02-07T08:43:09Z")

</div>

this is very hard to do without further explanations of your data model. Without knowing it, the question whether you can create a watch basically boils down to one question:

Can you create a search query out of your question/use-case that returns the data needed. If that is the case, you can easily create a watch. But this is the first thing you need to solve, completely independent from watcher.

if that is given, you can proceed and write a watch, share your watch and then we go from there.

This blog post might help you to create a short run/debug loop for watcher

> **[Watching the watches: Writing, debugging and testing watches
	  	 | Elastic](https://www.elastic.co/blog/watching-the-watches-writing-debugging-and-testing-watches)**
>
> TLDR; This blog post will outline how to efficiently write, execute, and debug watches. This will be useful if you are writing your own watches or if you have to debug watches written by your colleagu...

--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 7, 2018, 8:43am UTC](https://discuss.elastic.co/t/implementing-elasticsearch-1-0x-watcher-using-java/117880/3 "2018-03-07T08:43:17Z")

</div>

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