Hi All,
I've been using watcher with ES 5.6.3 and after updating to 6.1 the condition code is not working anymore.
Any help will be appreciated
Here is the error I have
 "exception": {
    "type": "script_exception",
    "reason": "runtime error",
    "script_stack": [
      "calls=ctx.payload.aggregations.origin;",
      "                              ^---- HERE"
    ],
    "script": "def docs=[];def status= false;def calls=ctx.payload.aggregations.origin;for (int i = 0; i < calls.buckets.size(); ++i) {if (calls.buckets[i].grand_total.value > 370){ docs.add(['from' : calls.buckets[i].key , 'gt' : calls.buckets[i].grand_total.value]);status=true} } ctx.vars.alerts=docs; return status",
    "lang": "painless",
    "caused_by": {
      "type": "null_pointer_exception",
      "reason": null,
      "stack_trace": "java.lang.NullPointerException\n\tat org.elasticsearch.painless.DefBootstrap$PIC.fallback(DefBootstrap.java:202)\n\tat org.elasticsearch.painless.PainlessScript$Script.execute(def docs=[];def status= false;def calls=ctx.payload.aggregations.origin;for (int i = 0; i < calls.buckets.size(); ++i) {if (calls.buckets[i].grand_total.value > 370){ docs.add(['from' : calls.buckets[i].key , 'gt' : calls.buckets[i].grand_total.value]);sta ...:65)\n\tat org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:105)\n\tat org.elasticsearch.xpack.watcher.condition.ScriptCondition.doExecute(ScriptCondition.java:86)\n\tat org.elasticsearch.xpack.watcher.condition.ScriptCondition.execute(ScriptCondition.java:77)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.executeInner(ExecutionService.java:464)\n\tat org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:315)\n\tat org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction.lambda$executeWatch$1(TransportExecuteWatchAction.java:154)\n\tat java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)\n\tat java.util.concurrent.FutureTask.run(FutureTask.java:266)\n\tat org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingRunnable.run(ThreadContext.java:568)\n\tat java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)\n\tat java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)\n\tat java.lang.Thread.run(Thread.java:748)\n"
Watcher code. (Working on ES 5.6.3)
{
  "trigger": {
    "schedule": {
      "interval": "30m"
    }
  },
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "temp_sbc"
        ],
        "types": [],
        "body": {
          "query": {
            "bool": {
              "filter": [
                {
                  "terms": {
                    "oper.keyword": [
                      "INTERIM",
                      "STOP"
                    ]
                  }
                },
                {
                  "bool": {
                    "must": [
                      {
                        "range": {
                          "ts_start": {
                            "gte": "2017-11-11T00:05:00.000Z",
                            "lte": "2017-11-11T00:28:00.000Z"
                          }
                        }
                      },
                      {
                        "range": {
                          "ts_stop": {
                            "gte": "2017-11-11T00:05:00.000Z",
                            "lte": "2017-11-11T00:28:00.000Z"
                          }
                        }
                      },
                      {
                        "terms": {
                          "dir.keyword": [
                            "O"
                          ]
                        }
                      }
                    ]
                  }
                }
              ]
            }
          },
          "aggs": {
            "origin": {
              "terms": {
                "field": "from.keyword",
                "size": 10000
              },
              "aggs": {
                "call_ref": {
                  "terms": {
                    "field": "call_ref.keyword",
                    "size": 10000
                  },
                  "aggs": {
                    "total_duration": {
                      "max": {
                        "field": "duration"
                      }
                    }
                  }
                },
                "grand_total": {
                  "sum_bucket": {
                    "buckets_path": "call_ref>total_duration"
                  }
                }
              }
            }
          }
        }
      }
    }
  },
  "condition": {
    "script": {
      "source": "def docs=[];def status= false;def calls=ctx.payload.aggregations.origin;for (int i = 0; i < calls.buckets.size(); ++i) {if (calls.buckets[i].grand_total.value > 370){ docs.add(['from' : calls.buckets[i].key , 'gt' : calls.buckets[i].grand_total.value]);status=true} } ctx.vars.alerts=docs; return status",
      "lang": "painless"
    }
  },
  "actions": {
    "my-logging-action": {
      "logging": {
        "level": "info",
        "text": "There are {{#ctx.vars.alerts}} From: {{from}}: Total {{gt}}{{/ctx.vars.alerts}}"
      }
    }
  }
}
            