Team,
I have an ES hosted cloud solution loading in all documents from our purchase path including the products, prices etc.
I want to add a watcher that is scheduled to run every 5 minutes and compares to the previous 5 minutes and alert if there was a sharp decrease. Purchases vary throughout the day so this dynamic.
I have the following watcher but getting a null point exception on the scripting for the condition. Appreciate your assistance:
PUT /_watcher/watch/purchase-decrease-test
{ "trigger" : { "schedule" : { "interval" : "5m" } }, "input" : { "search" : { "request": { "indices": "purchases", "body": { "size": 0, "query": { "bool": { "filter": { "range": { "datetimestamp_created": { "from": "now-10m", "to": "now" } } } } }, "aggs": { "five_min":{ "filters": { "filters": { "latest5":{ "range":{ "datetimestamp_created": { "gte": "now-5m", "lte": "now"} } }, "previous5": { "range": { "datetimestamp_created": { "gte": "now-10m", "lt": "now-5m"} } } } } } } } } }, "condition" : { "script": { "inline": "return ctx.payload.aggregations.five_min.bucket.latest5.value < 0.5 *ctx.payload.aggregations.five_min.buckets.previous5.value" } }, "transform" : {}, "actions" : { "email_admin" : { "email": { "to": "myemail@mydomain.com", "subject": "No Purchases found for test", "body": "" } } } }
When I run this is the error:
"exception": {
"type": "script_exception",
"reason": "runtime error",
"script_stack": [
"return ctx.payload.aggregations.five_min.bucket.latest5.value < 0.5 *ctx.payload.aggregations.five_min.buckets.previous5.value",
" ^---- HERE"
],
"script": "return ctx.payload.aggregations.five_min.bucket.latest5.value < 0.5 *ctx.payload.aggregations.five_min.buckets.previous5.value",
"lang": "painless",
"caused_by": {
"type": "null_pointer_exception",
"reason": null,
"stack_trace": """
java.lang.NullPointerException
at org.elasticsearch.painless.DefBootstrap$PIC.fallback(DefBootstrap.java:200)
at org.elasticsearch.painless.Executable$Script.execute(return ctx.payload.aggregations.five_min.bucket.latest5.value < 0.5 *ctx.payload.aggregations.five_min.buckets.previous5.value:48)
at org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:123)
at org.elasticsearch.xpack.watcher.condition.ScriptCondition.doExecute(ScriptCondition.java:94)
at org.elasticsearch.xpack.watcher.condition.ScriptCondition.execute(ScriptCondition.java:84)
at org.elasticsearch.xpack.watcher.execution.ExecutionService.executeInner(ExecutionService.java:391)
at org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:275)
at org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction.masterOperation(TransportExecuteWatchAction.java:136)
at org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction.masterOperation(TransportExecuteWatchAction.java:64)
at org.elasticsearch.action.support.master.TransportMasterNodeAction.masterOperation(TransportMasterNodeAction.java:87)
at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction$2.doRun(TransportMasterNodeAction.java:166)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:613)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
"""
},
"stack_trace": """
ScriptException[runtime error]; nested: NullPointerException;
at org.elasticsearch.painless.ScriptImpl.convertToScriptException(ScriptImpl.java:181)
at org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:128)
at org.elasticsearch.xpack.watcher.condition.ScriptCondition.doExecute(ScriptCondition.java:94)
at org.elasticsearch.xpack.watcher.condition.ScriptCondition.execute(ScriptCondition.java:84)
at org.elasticsearch.xpack.watcher.execution.ExecutionService.executeInner(ExecutionService.java:391)
at org.elasticsearch.xpack.watcher.execution.ExecutionService.execute(ExecutionService.java:275)
at org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction.masterOperation(TransportExecuteWatchAction.java:136)
at org.elasticsearch.xpack.watcher.transport.actions.execute.TransportExecuteWatchAction.masterOperation(TransportExecuteWatchAction.java:64)
at org.elasticsearch.action.support.master.TransportMasterNodeAction.masterOperation(TransportMasterNodeAction.java:87)
at org.elasticsearch.action.support.master.TransportMasterNodeAction$AsyncSingleAction$2.doRun(TransportMasterNodeAction.java:166)
at org.elasticsearch.common.util.concurrent.ThreadContext$ContextPreservingAbstractRunnable.doRun(ThreadContext.java:613)
at org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.lang.NullPointerException
at org.elasticsearch.painless.DefBootstrap$PIC.fallback(DefBootstrap.java:200)
at org.elasticsearch.painless.Executable$Script.execute(return ctx.payload.aggregations.five_min.bucket.latest5.value < 0.5 *ctx.payload.aggregations.five_min.buckets.previous5.value:48)
at org.elasticsearch.painless.ScriptImpl.run(ScriptImpl.java:123)
... 13 more
"""