# Create a condition in EQL/ES|QL query for alert

**URL:** <https://discuss.elastic.co/t/create-a-condition-in-eql-es-ql-query-for-alert/375755>\
**Category:** Elastic Security\
**Created:** [March 12, 2025, 3:32am UTC](https://discuss.elastic.co/t/create-a-condition-in-eql-es-ql-query-for-alert/375755 "2025-03-12T03:32:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Discentius\_Crux](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/discentius_crux/32/140839_2.png) [@Discentius\_Crux](https://discuss.elastic.co/u/Discentius_Crux)\
**Post date:** [March 12, 2025, 3:32am UTC](https://discuss.elastic.co/t/create-a-condition-in-eql-es-ql-query-for-alert/375755/1 "2025-03-12T03:32:29Z")

</div>

Hi,

Can we create a condition using EQL or ESQL query to raise an alert?

such as

if there is any failed login more than twice then followed up by success it will raise?

```auto
{
  "query": """
    sequence by user.name with maxspan=10m
      [authentication where event.outcome == "failure"]
      [authentication where event.outcome == "failure"]
      [authentication where event.outcome == "success"]
      [authentication where event.category == "logoff"]
  """
}

```

can we like [authentication where event.outcome == "failure"] \> 2?

or to raise an IoC that truly detect without any preventation action followed up?

```auto
sequence by source.ip
  [
    any where
      event.category in ("network", "malware") and
      event.action == "Detect" and
      (IOC)
  ]
  not followed by
  [
    any where
      event.category in ("network", "malware") and
      event.action == "Prevent" and
      (IOC)
  ]

```

---

<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 9, 2025, 3:33am UTC](https://discuss.elastic.co/t/create-a-condition-in-eql-es-ql-query-for-alert/375755/2 "2025-04-09T03:33:03Z")

</div>

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