# Issue trying to make ponctuality test using watchers

**URL:** <https://discuss.elastic.co/t/issue-trying-to-make-ponctuality-test-using-watchers/168809>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [February 18, 2019, 10:50am UTC](https://discuss.elastic.co/t/issue-trying-to-make-ponctuality-test-using-watchers/168809 "2019-02-18T10:50:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![philippeE](https://avatars.discourse-cdn.com/v4/letter/p/6bbea6/32.png) [@philippeE](https://discuss.elastic.co/u/philippeE)\
**Post date:** [February 18, 2019, 10:50am UTC](https://discuss.elastic.co/t/issue-trying-to-make-ponctuality-test-using-watchers/168809/1 "2019-02-18T10:50:12Z")

</div>

Hi all,  
I have an issue and I hope you can help me.  
Here is my code:

> ```
> PUT _xpack/watcher/watch/test_ponctuality
> {
> "trigger" : { 
> "schedule" : {
> "interval" : "10s"
> }
> },
> "input" : { 
> "chain" : {
> "inputs" : [
> {
> "first" : {
> "search" : {
> "request" : {
> "indices" : ["fileparams"],
> "body" : {
> "query" : {
> "match_all" : {}
> }
> }
> }
> }
> }
> },
> {
> "second" : {
> "search" : {
> "request" : {
> "indices" : ["ponctuality"],
> "body" : {
> "query" : {
> "match_all" : { }
> }
> }
> }
> }
> }
> }
> ]}},
> "condition" : {
> "script" : {
> "lang" : "painless",
> "source": """
> for(int i=0;i<ctx.payload.first.hits.total;i++){
> for(int j=0;j<ctx.payload.second.hits.total;j++){
> if(ctx.payload.first.hits.hits.i._source.file_id==ctx.payload.second.hits.hits.j._source.interfaceSequence){
> if (ctx.payload.first.hits.hits.i._source.scheduledArrivalTime< executionDate){
> ctx.payload.second.hits.hits.j._source.ponctuality = "ok";
>                             
> }else{
> ctx.payload.second.hits.hits.j._source.ponctuality = "late"
>                                 
> }
> }
> }
> }
>                  
> return true; 
>                  
> """
> }
> },
> "actions" : { 
> "index_payload" : { 
> "index" : {
> "index" : "test",
> "doc_type":"doc"
> }
> }
> }
> }
> 
> ```

**Code explanation**  
I have an Index fileparams in witch documents say: I want this "file\_id" to arrive before "scheduledArrivalTime" I am trying to use watcher to survey the ponctuality data and if they are late add an attribute "ponctuality" at "late" and if it arrived on time put it at "ok".  
This code above des not work and the only error Elasticsearch show me is :`[2019-02-18T11:46:55,054][WARN][o.e.x.w.e.ExecutionService] [CUiEBk2] failed to execute watch [test_ponctuality]`

I am obviously new at elasticsearch so maybe I am not using the right tools to do what I need. I am open to every suggestions^^.  
Please advise.

---

<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 18, 2019, 10:50am UTC](https://discuss.elastic.co/t/issue-trying-to-make-ponctuality-test-using-watchers/168809/2 "2019-03-18T10:50:20Z")

</div>

Closed on March 18, 2019, 10:50am UTC

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