# Detection rule kquery will not trigger but the query match

**URL:** <https://discuss.elastic.co/t/detection-rule-kquery-will-not-trigger-but-the-query-match/273085>\
**Category:** SIEM\
**Created:** [May 15, 2021, 3:59pm UTC](https://discuss.elastic.co/t/detection-rule-kquery-will-not-trigger-but-the-query-match/273085 "2021-05-15T15:59:03Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![leon3](https://avatars.discourse-cdn.com/v4/letter/l/cab0a1/32.png) [@leon3](https://discuss.elastic.co/u/leon3)\
**Post date:** [May 15, 2021, 3:59pm UTC](https://discuss.elastic.co/t/detection-rule-kquery-will-not-trigger-but-the-query-match/273085/1 "2021-05-15T15:59:03Z")

</div>

Hi  
I have a weird issue when use kquery in detection rules.  
I use a simple query to match a field and triggering action for that but the rule will not be triggered while its query is matching in the specified interval.  
I could see that the query is matching in the "preview result" pane but on the rule monitoring it shows the rule successfully executed but no results in detections.

another weird point is when I delete the rule and recreate it, it will match but it seems it will match only once.

I'm using ElasticCloud with the default configuration. I see no errors in rule monitoring only successful messages.

---

<div class="post-metadata">

**Author:** ![Mike\_Paquette](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_paquette/32/119011_2.png) [@Mike\_Paquette](https://discuss.elastic.co/u/Mike_Paquette)\
**Post date:** [May 17, 2021, 11:54am UTC](https://discuss.elastic.co/t/detection-rule-kquery-will-not-trigger-but-the-query-match/273085/2 "2021-05-17T11:54:27Z")

</div>

Hi @leon3, welcome to our community!

We're glad you are trying out the Elastic Security solution, and hopefully we can get to the bottom of your rule questions and get your detections running smoothly.

Please allow me to start with a very basic question, how are you determining that the rule is not triggering?

If you are able to share your rule with us (be sure to mask out any confidential information), that could help us spot anything that might be contributing to your issue.

Also, please let us know a little bit about your environment:

1. What version of the Elastic Stack you are running in Elastic Cloud?
2. How are you sending your data into Elastic Cloud?
3. Is your data represented in an ECS-compliant format?

Meanwhile, here are some [monitoring and troubleshooting tips](https://www.elastic.co/guide/en/security/current/alerts-ui-monitor.html) for when you are missing alerts.

One thing to keep in mind is that the "Quick query preview" function during rule creation **excludes** the effects of rule exceptions and timestamp overrides. So if your rule has either of these applied, that could lead to a difference in behavior between the preview query and the rule execution.

Another idea: You mention a "triggering action" for the rule. Be sure to check out your rule _Actions frequency_ settings. If you select one of the settings below, you will only get the notification one time per (hour/day/week).

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/0/3/03a500d345ed786044d8915b005bf57318c3fdcd.jpeg)

---

<div class="post-metadata">

**Author:** ![aditi\_salunke](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/aditi_salunke/32/85600_2.png) [@aditi\_salunke](https://discuss.elastic.co/u/aditi_salunke)\
**Post date:** [May 29, 2021, 4:56pm UTC](https://discuss.elastic.co/t/detection-rule-kquery-will-not-trigger-but-the-query-match/273085/3 "2021-05-29T16:56:33Z")

</div>

Hi @Mike_Paquette @leon3

I am facing kinda same issue. Can you please help

Here is the link of issue:

> [@Detection rules which are based on indices where host field is fetched as string are not generating the alerts](https://discuss.elastic.co/t/detection-rules-which-are-based-on-indices-where-host-field-is-fetched-as-strong-are-not-generating-the-alerts/274406):
>
> Bulk Indexing of signals failed: object mapping for [host] tried to parse field [host] as object, but found a concrete value name: "\<rule name\>:\<random id\>" rule id: "\<rule\_id\>" signals index: ".siem-signals-default" So above reason we are getting in 'failure history' of some rules Though the query is triggering alerts in preview while creating rule after activation it's not triggering any alerts Things which i found might be concern: In X index, mapping is dynamic, host field is present i…

---

<div class="post-metadata">

**Author:** ![Mike\_Paquette](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mike_paquette/32/119011_2.png) [@Mike\_Paquette](https://discuss.elastic.co/u/Mike_Paquette)\
**Post date:** [May 31, 2021, 12:03pm UTC](https://discuss.elastic.co/t/detection-rule-kquery-will-not-trigger-but-the-query-match/273085/4 "2021-05-31T12:03:54Z")

</div>

Hi @aditi_salunke I think your issue is different (you are receiving failure messages - @leon3 is not) and appears, as you suspect, to be caused by a mapping conflict in your data, with regards to the host field.

I want to make sure you are aware that the Elastic SIEM/Security app, including its detection rules, signals, and detection alerts, requires your data to be indexed in an ECS-compliant format. [ECS](https://www.elastic.co/guide/en/ecs/current/ecs-reference.html) is an open source, community-developed schema that specifies field names and Elasticsearch data types for each field, and provides descriptions and example usage.

The easiest way to get your data in ECS-compliant format is to use an Elastic-supplied beat module, (e.g., [filebeat](https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-modules-overview.html) or Elastic Agent integration), which will ingest and index your data in an ECS-compliant format. Elastic provides a growing list of these integrations that you can find on our [Integrations page](https://www.elastic.co/integrations?solution=security).

Where is your data coming from? Perhaps there's an integration that can help?

[General guidelines](https://www.elastic.co/guide/en/ecs/current/ecs-guidelines.html) for creating ECS-compliant data:

1. Each indexed document (e.g., your log, event, etc.) MUST have the `@timestamp` field.
2. Your index mapping template must specify the [Elasticsearch field data type](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-types.html) for each field as defined by ECS. For example, your `@timestamp` field must be of the `date` field data type, etc.. This ensures that there will not be any mapping conflicts in your indices.
3. The original fields from your log/event SHOULD be copied/renamed/converted to the corresponding ECS-defined field name and data type.
4. Additional ECS fields, such as the [ECS Categorization fields](https://www.elastic.co/guide/en/ecs/current/ecs-category-field-values-reference.html) SHOULD be populated for each log/event, to allow proper inclusion of your data into dashboards and detection rules.

Here's a simple graphic that I created to help get this point across.

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/1/3/134745457846e5b5ca6802e79e7bb2b08a09c7dc.jpeg)

Please let us know is this helps.

---

<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 28, 2021, 12:04pm UTC](https://discuss.elastic.co/t/detection-rule-kquery-will-not-trigger-but-the-query-match/273085/5 "2021-06-28T12:04:24Z")

</div>

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