# Watcher alerts null pointer error

**URL:** https://discuss.elastic.co/t/watcher-alerts-null-pointer-error/273268
**Category:** Kibana
**Tags:** elastic-stack-monitoring, elastic-stack-alerting
**Created:** [May 18, 2021, 10:37am UTC](https://discuss.elastic.co/t/watcher-alerts-null-pointer-error/273268 "2021-05-18T10:37:49Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Roy\_Levy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_levy/32/61613_2.png) [@Roy\_Levy](https://discuss.elastic.co/u/Roy_Levy)
#### Post date: [May 18, 2021, 10:37am UTC](https://discuss.elastic.co/t/watcher-alerts-null-pointer-error/273268/1 "2021-05-18T10:37:49Z")

</div>

Hey,

I'm trying to get Kibana Watcher alerts to insert documents to new index.  
When simulating the script I'm getting the following error:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/3/039c1698dca9fa8261f2ea5ecb12446b0d42f796.png)

The error seems to be with the aggregations field - null pointer. But I did specify the Alert aggregation and make sure it's got documents with the condition:

```auto
"condition": {
    "array_compare": {
      "ctx.payload.aggregations.Alerts.buckets": {
        "path": "doc_count",
        "gte": {
          "value": 10,
          "quantifier": "some"
        }
      }
    }
  }

```

Am I missing anything?

---

<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: [May 18, 2021, 10:46am UTC](https://discuss.elastic.co/t/watcher-alerts-null-pointer-error/273268/2 "2021-05-18T10:46:55Z")

</div>

can you share a sample search response?

---

<div class="post-metadata">

### Author: ![Roy\_Levy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/roy_levy/32/61613_2.png) [@Roy\_Levy](https://discuss.elastic.co/u/Roy_Levy)
#### Post date: [May 18, 2021, 11:17am UTC](https://discuss.elastic.co/t/watcher-alerts-null-pointer-error/273268/4 "2021-05-18T11:17:55Z")

</div>

If you are reffering to the dev tools search for my query it is showing null pointer exception:

```auto
{
  "took" : 36,
  "timed_out" : false,
  "_shards" : {
    "total" : 210,
    "successful" : 165,
    "skipped" : 165,
    "failed" : 45,
    "failures" : [
      {
        "shard" : 0,
        "index" : "index-2",
        "node" : "CqUsdMeQuRXQ",
        "reason" : {
          "type" : "null_pointer_exception",
          "reason" : null
        }
      },
      {
        "shard" : 0,
        "index" : "index-3",
        "node" : "CqUazb8Ap2MMuRXQ",
        "reason" : {
          "type" : "null_pointer_exception",
          "reason" : null
        }
      },
      {
        "shard" : 0,
        "index" : "index-4",
        "node" : "MFi-XsjYS9caC6nUQ",
        "reason" : {
          "type" : "null_pointer_exception",
          "reason" : null
        }
      },
      {
        "shard" : 0,
        "index" : "index-5",
        "node" : "CqUazok1QJmb8Ap2XQ",
        "reason" : {
          "type" : "null_pointer_exception",
          "reason" : null
        }
      }
    ]
  },
  "hits" : {
    "total" : {
      "value" : 0,
      "relation" : "eq"
    },
    "max_score" : 0.0,
    "hits" : []
  }
}

```

I'm using Scripted Fields in my query - maybe that could be problematic in queries? because when I'm omitting them the query is good and I'm getting the results.

Edit:  
The scripted fields which I'm using are nullable and I think that is the cause - is there any way to check for null inside the Watcher script?

---

<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: [June 15, 2021, 11:18am UTC](https://discuss.elastic.co/t/watcher-alerts-null-pointer-error/273268/5 "2021-06-15T11:18:35Z")

</div>

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