# Alert results are showing incorrect

**URL:** https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647
**Category:** Kibana
**Tags:** elastic-stack-alerting
**Created:** [March 2, 2022, 4:27pm UTC](https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647 "2022-03-02T16:27:02Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![vishal\_bisa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_bisa/32/96094_2.png) [@vishal\_bisa](https://discuss.elastic.co/u/vishal_bisa)
#### Post date: [March 2, 2022, 4:27pm UTC](https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647/1 "2022-03-02T16:27:02Z")

</div>

Hi Team,

I have created a watcher to detect for failed status in a particular index, attached the screenshot for reference.  
the watcher seems to be working fine, but when i have observed care fully the results are quite wrong.  
in the discover section i could see 2 instances of failed keyword in last 24hrs but in my watcher simulate i am getting the count as 6.  
Can any one please shed some light what i am doing wrong.  
if i remove this piece of code _ **"{ "range" : { "@timestamp" : { "from": "now-1d", "to": "now" } } },** _" from watcher i get the whole result as 93 which matches with my discover section.  
watcher code :

```auto
  "input": {
    "search": {
      "request": {
        "search_type": "query_then_fetch",
        "indices": [
          "logs-*"
        ],
        "rest_total_hits_as_int": true,
        "body": {
          "size": 0,
          "query" : {
          "bool" : {
          "filter" : [
        { "range" : { "@timestamp" : { "from": "now-1d", "to": "now" } } },
        { "match" : { "Status.keyword": "Failed" }}
    ]
  }
}
        }
      }
    }
  },
  "condition": {
    "compare": {
      "ctx.payload.hits.total": {
        "gte": 1
      }
    }
  },
  "actions": {
    "send_email": {
      "email": {
        "profile": "standard",
        "to": [
          ""
        ],
        "subject": "Watcher Notification",
        "body": {
          "text": "{{ctx.payload.hits.total}}"
        }
      }
    }
  }
}

```

Simulate result --\> removed the top lines

```auto
  "result": {
    "execution_time": "2022-03-02T16:07:48.513Z",
    "execution_duration": 16,
    "input": {
      "type": "search",
      "status": "success",
      "payload": {
        "_shards": {
          "total": 30,
          "failed": 0,
          "successful": 30,
          "skipped": 0
        },
        "hits": {
          "hits": [],
          "total": 6,
          "max_score": null
        },
        "took": 15,
        "timed_out": false
      },
      "search": {
        "request": {
          "search_type": "query_then_fetch",
          "indices": [
            "logs-*"
          ],
          "rest_total_hits_as_int": true,
          "body": {
            "size": 0,
            "query": {
              "bool": {
                "filter": [
                  {
                    "range": {
                      "@timestamp": {
                        "from": "now-1d",
                        "to": "now"
                      }
                    }
                  },
                  {
                    "match": {
                      "Status.keyword": "Failed"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "condition": {
      "type": "compare",
      "status": "success",
      "met": true,
      "compare": {
        "resolved_values": {
          "ctx.payload.hits.total": 6
        }
      }
    },
    "actions": [
      {
        "id": "send_email",
        "type": "email",
        "status": "simulated",
        "email": {
          "message": {
            "id": "send_email __inlined__ 5b16ca04-0632-427d-8c13-2c9c132ec8b0-2022-03-02T16:07:48.513492828Z_27",
            "sent_date": "2022-03-02T16:07:48.530859562Z",
            "to": [
              "xxxx@gmail.com"
            ],
            "subject": "Watcher Notification",
            "body": {
              "text": "6 "
            }
          }
        }
      }
    ]
  },
  "messages": []
}

```

 ![test](https://us1.discourse-cdn.com/elastic/original/3X/5/e/5e40f7dfead7241864489acc08c0dbd72e951938.png)

---

<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: [March 3, 2022, 8:31am UTC](https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647/2 "2022-03-03T08:31:36Z")

</div>

The query itself looks ok, one thing that stands out. You are using a `match` query, so the `Failed` term will not get analyzed when running against a keyword field.Is it possible, that you have documents with `Failed` and `failed` as values and this is causing a discrepancy?

---

<div class="post-metadata">

### Author: ![vishal\_bisa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_bisa/32/96094_2.png) [@vishal\_bisa](https://discuss.elastic.co/u/vishal_bisa)
#### Post date: [March 3, 2022, 9:38am UTC](https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647/3 "2022-03-03T09:38:32Z")

</div>

> [@spinscale](#):
>
> You are using a `match` query, so the `Failed` term will not get analyzed when running against a keyword field

Apologies @spinscale Didn't get this above point ?  
also i have crosschecked and i could find only 3-4 status (Completed/Queued/Failed/-)  
but if i remove the timestamp range the result is matched with the total no of failures

 ![reference](https://us1.discourse-cdn.com/elastic/original/3X/c/b/cb69d1423eb4fc40b88d9f83051136891719cda5.png)

---

<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: [March 3, 2022, 9:52am UTC](https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647/4 "2022-03-03T09:52:28Z")

</div>

Can you share the timestamps of documents that are supposed to match but do not?

Your sample screenshot is only checking 500 docs, but not the whole dataset within a time range, so this cannot be trusted without running exact queries (that is part of Kibana's discover functionality).

One more thing to check: Judging from the found shards in the watcher response, 30 shards are hit. Does the same apply, when you the exact same query within dev tools as the elastic adminuser?

---

<div class="post-metadata">

### Author: ![vishal\_bisa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_bisa/32/96094_2.png) [@vishal\_bisa](https://discuss.elastic.co/u/vishal_bisa)
#### Post date: [March 3, 2022, 12:34pm UTC](https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647/5 "2022-03-03T12:34:20Z")

</div>

sharing the Timestamps of the documents below  
yes I have observed that the watcher result matches when i apply the same query in dev tools, currently the value is 7 but in discover it shows me only 4 records.  
also i did a visualization in a pie chart for completed and failed status here the results are different when compared to discover and watcher .

 ![reference](https://us1.discourse-cdn.com/elastic/original/3X/9/a/9a0d6f9ff111056680b06c5a48247b8a6f3dd17f.png)  
 ![24hrs](https://us1.discourse-cdn.com/elastic/original/3X/c/4/c4ffaba9d1e26f0be30211a2df1d5bacb3d25b57.png)

 ![pie](https://us1.discourse-cdn.com/elastic/original/3X/6/8/68be5114b2409e8e0d7f140326ddbf99a26e7bbd.png)

---

<div class="post-metadata">

### Author: ![vishal\_bisa](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vishal_bisa/32/96094_2.png) [@vishal\_bisa](https://discuss.elastic.co/u/vishal_bisa)
#### Post date: [March 10, 2022, 11:03am UTC](https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647/6 "2022-03-10T11:03:38Z")

</div>

@spinscale can you please help

---

<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: [April 7, 2022, 11:04am UTC](https://discuss.elastic.co/t/alert-results-are-showing-incorrect/298647/7 "2022-04-07T11:04:21Z")

</div>

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