# Create an alert based on contradicting logs

**URL:** <https://discuss.elastic.co/t/create-an-alert-based-on-contradicting-logs/253050>\
**Category:** Kibana\
**Created:** [October 22, 2020, 6:06pm UTC](https://discuss.elastic.co/t/create-an-alert-based-on-contradicting-logs/253050 "2020-10-22T18:06:47Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mimoo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mimoo/32/24892_2.png) [@mimoo](https://discuss.elastic.co/u/mimoo)\
**Post date:** [October 22, 2020, 6:06pm UTC](https://discuss.elastic.co/t/create-an-alert-based-on-contradicting-logs/253050/1 "2020-10-22T18:06:47Z")

</div>

Hello,

I am trying to figure out alerts, and if Kibana is the best place to setup these alerts, or if it'd be better for me to write a program that queries elastic search instead.

I'm in a situation where I log tuples of the form `(a, b, c, e)` and want to make sure that when a, b, and c are the same, then e is the same. In other words, there shouldn't be any `(a, b, c, e)` and `(a, b, c, e')` for `e != e'`

---

<div class="post-metadata">

**Author:** ![rashmi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rashmi/32/16391_2.png) [@rashmi](https://discuss.elastic.co/u/rashmi)\
**Post date:** [October 23, 2020, 5:51pm UTC](https://discuss.elastic.co/t/create-an-alert-based-on-contradicting-logs/253050/2 "2020-10-23T17:51:35Z")

</div>

I think this could be achieved using the conditions in Kibana alerting feature.

> **[Defining alerts | Kibana Guide \[7.9\] | Elastic](https://www.elastic.co/guide/en/kibana/current/defining-alerts.html#defining-alerts-type-conditions)**

But am going to tag @Patrick_Mueller for more detailed answer .

Thanks  
Rashmi

---

<div class="post-metadata">

**Author:** ![Patrick\_Mueller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrick_mueller/32/109425_2.png) [@Patrick\_Mueller](https://discuss.elastic.co/u/Patrick_Mueller)\
**Post date:** [October 26, 2020, 6:17pm UTC](https://discuss.elastic.co/t/create-an-alert-based-on-contradicting-logs/253050/3 "2020-10-26T18:17:57Z")

</div>

> [@rashmi](#):
>
> I think this could be achieved using the conditions in Kibana alerting feature.

I'm not quite sure of that. I don't think the Index threshold alert can do this, as it doesn't have any special filtering capabilities yet. It's possible the Log or Metric alerts could do this, as they do have filtering, but I'm not sure they can filter based on the suggested constraint.

We do have a feature enhancement issue open to create a more open-ended "search" alert that would presumably allow for the suggested constraint. Feel free to add this example as a use case, @mimoo - [New "search alert" type based on ES dsl query and hit count · Issue #61313 · elastic/kibana · GitHub](https://github.com/elastic/kibana/issues/61313)

Beyond that, I've often wondered whether creating an elasticsearch alias with a filter would be an acceptable way to handle this, today. The idea is that you create an alias of the indices you want to query on, and add a filter to that, so when querying the index via the alias, you would only see the documents which match the constraint. The alert could then be an index threshold looking for count \> 0.

For more info on filtered aliases, see [Aliases API | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-aliases.html#filtered)

---

<div class="post-metadata">

**Author:** ![mimoo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mimoo/32/24892_2.png) [@mimoo](https://discuss.elastic.co/u/mimoo)\
**Post date:** [November 6, 2020, 3:09am UTC](https://discuss.elastic.co/t/create-an-alert-based-on-contradicting-logs/253050/4 "2020-11-06T03:09:33Z")

</div>

thanks for the responses! I've tried aggregating all the fields (a, b, c) together instead using nested aggregation, and then counting the number of fields e I get, but no luck so far. I'll try the alias way, not sure I understand what I need to do though.

BTW, what would be another acceptable way to build alerts on top of that data? Writing a script that queries elastic search periodically and handles the heavier logic?

---

<div class="post-metadata">

**Author:** ![Patrick\_Mueller](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/patrick_mueller/32/109425_2.png) [@Patrick\_Mueller](https://discuss.elastic.co/u/Patrick_Mueller)\
**Post date:** [November 6, 2020, 2:13pm UTC](https://discuss.elastic.co/t/create-an-alert-based-on-contradicting-logs/253050/5 "2020-11-06T14:13:58Z")

</div>

> [@mimoo](#):
>
> BTW, what would be another acceptable way to build alerts on top of that data? Writing a script that queries Elasticsearch periodically and handles the heavier logic?

Good question, that I don't have an answer for. I'm not sure any of the solution-oriented alerts (ie, observability and security alerts) are abstract enough to do this directly.

One approach would be to create a job which looks through the data, and writes the matches you are looking for to a separate index; presumably the index would store `a`, `,b`, `c`, `e` and `e'`, so you can see all the values. Then use the index threshold alert with a count aggregation, looking for those documents in the separate index.

You might want to look into [EQL](https://www.elastic.co/guide/en/elasticsearch/reference/current/eql.html) as a way to search for those matches. Not sure if it can do what you need, but it does have a concept of letting you match a sequence of events. We don't yet have a generic alert that would allow you to use EQL, but I'd be interested in finding out if EQL worked out for you for this case, and so potentially an alert that used EQL might be a useful thing to have. I suspect we will eventually have an alert that supports EQL.

I'd also post the question about your query up at the [ElasticSearch topic](https://discuss.elastic.co/c/elastic-stack/elasticsearch/6) - there is likely someone there who knows more about building queries like this.

---

<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:** [December 4, 2020, 2:14pm UTC](https://discuss.elastic.co/t/create-an-alert-based-on-contradicting-logs/253050/6 "2020-12-04T14:14:01Z")

</div>

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