Skip to content

[Security Solution][Detection Engine] adds support of identical ids across multiple indices during ES|QL rule pagination requests#219278

Merged
vitaliidm merged 52 commits intoelastic:mainfrom
vitaliidm:de_9_1/esql_identical_ids
Jul 11, 2025
Merged

[Security Solution][Detection Engine] adds support of identical ids across multiple indices during ES|QL rule pagination requests#219278
vitaliidm merged 52 commits intoelastic:mainfrom
vitaliidm:de_9_1/esql_identical_ids

Conversation

@vitaliidm
Copy link
Copy Markdown
Contributor

@vitaliidm vitaliidm commented Apr 25, 2025

Summary

Setup

Setup 2 indices with identical documents ids
PUT close_alerts_1
PUT close_alerts_1/_mapping
{
  "properties": {
    "@timestamp": {
      "type": "date"
    },
    "agent": {
      "properties": {
        "name": {
          "type": "keyword"
        }
      }
    },
    "source": {
      "properties": {
        "ip": {
          "type": "ip"
        }
      }
    },
    "destination": {
      "properties": {
        "ip": {
          "type": "ip"
        },
        "port": {
          "type": "keyword"
        }
      }
    }
  }
}


PUT close_alerts_2
PUT close_alerts_2/_mapping
{
  "properties": {
    "@timestamp": {
      "type": "date"
    },
    "agent": {
      "properties": {
        "name": {
          "type": "keyword"
        }
      }
    },
    "source": {
      "properties": {
        "ip": {
          "type": "ip"
        }
      }
    },
    "destination": {
      "properties": {
        "ip": {
          "type": "ip"
        },
        "port": {
          "type": "keyword"
        }
      }
    }
  }
}


POST close_alerts_1/_doc/CFnnxZcBgU3wmL9Lp7xG
{
 "@timestamp": "2025-07-01T09:26:30.425Z",
 "source.ip": "127.0.0.1",
 "destination.ip": "127.0.0.1",
 "destination.port": 1,
 "agent.name": "test-0"
}

POST close_alerts_2/_doc/CFnnxZcBgU3wmL9Lp7xG
{
 "@timestamp": "2025-07-01T09:26:30.425Z",
 "source.ip": "127.0.0.1",
 "destination.ip": "127.0.0.1",
 "destination.port": 1,
 "agent.name": "test-0"
}

Exported rule Test rule

query before

POST _query/async?drop_null_columns=true&allow_partial_results=true
{
  "query": "from close_alerts* METADATA _id, _index | limit 101",
  "filter": {
    "bool": {
      "filter": [
        {
          "range": {
            "@timestamp": {
              "lte": "2025-07-01T12:26:45.110Z",
              "gte": "2025-06-30T11:56:45.110Z",
              "format": "strict_date_optional_time"
            }
          }
        },
        {
          "bool": {
            "must": [],
            "filter": [],
            "should": [],
            "must_not": []
          }
        }
      ],
      "must_not": {
        "ids": {
          "values": [
            "CFnnxZcBgU3wmL9Lp7xG"
          ]
        }
      }
    }
  },
  "wait_for_completion_timeout": "4m",
  "keep_alive": "60s"
}

query after

POST _query/async?drop_null_columns=true&allow_partial_results=true
{
  "query": "from close_alerts* METADATA _id, _index | limit 101",
  "filter": {
    "bool": {
      "filter": [
        {
          "range": {
            "@timestamp": {
              "lte": "2025-07-01T12:27:57.472Z",
              "gte": "2025-06-30T11:57:57.472Z",
              "format": "strict_date_optional_time"
            }
          }
        },
        {
          "bool": {
            "must": [],
            "filter": [],
            "should": [],
            "must_not": []
          }
        }
      ],
      "must_not": [
        {
          "bool": {
            "filter": [
              {
                "ids": {
                  "values": [
                    "CFnnxZcBgU3wmL9Lp7xG"
                  ]
                }
              },
              {
                "term": {
                  "_index": "close_alerts_1"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "filter": [
              {
                "ids": {
                  "values": [
                    "CFnnxZcBgU3wmL9Lp7xG"
                  ]
                }
              },
              {
                "term": {
                  "_index": "close_alerts_2"
                }
              }
            ]
          }
        }
      ]
    }
  },
  "wait_for_completion_timeout": "4m",
  "keep_alive": "60s"
}

vitaliidm added 20 commits April 3, 2025 17:08
…ion in case of alerts deduplication"

This reverts commit 28cfab6.
…cross multiple indices during ES|QL rule pagination requests
@vitaliidm vitaliidm self-assigned this Apr 25, 2025
@vitaliidm vitaliidm added Team:Detection Engine Security Solution Detection Engine Area release_note:skip Skip the PR/issue when compiling release notes backport:version Backport to applied version labels v9.1.0 v8.19.0 labels Apr 25, 2025
@kibanamachine
Copy link
Copy Markdown
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#8503

[❌] x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/rule_execution_logic/esql/trial_license_complete_tier/configs/ess.config.ts: 173/200 tests passed.

see run history

@kibanamachine
Copy link
Copy Markdown
Contributor

Flaky Test Runner Stats

🎉 All tests passed! - kibana-flaky-test-suite-runner#8507

[✅] x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/rule_execution_logic/esql/trial_license_complete_tier/configs/ess.config.ts: 200/200 tests passed.

see run history

@kibanamachine
Copy link
Copy Markdown
Contributor

Flaky Test Runner Stats

🟠 Some tests failed. - kibana-flaky-test-suite-runner#8511

[❌] x-pack/test/security_solution_api_integration/test_suites/detections_response/detection_engine/rule_execution_logic/esql/trial_license_complete_tier/configs/ess.config.ts: 174/200 tests passed.

see run history

@vitaliidm vitaliidm marked this pull request as ready for review July 2, 2025 16:53
@vitaliidm vitaliidm requested a review from a team as a code owner July 2, 2025 16:53
@vitaliidm vitaliidm requested a review from dhurley14 July 2, 2025 16:53
@elasticmachine
Copy link
Copy Markdown
Contributor

Pinging @elastic/security-detection-engine (Team:Detection Engine)

Copy link
Copy Markdown
Contributor

@dhurley14 dhurley14 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@elasticmachine
Copy link
Copy Markdown
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

History

cc @vitaliidm

@vitaliidm vitaliidm merged commit 4f6577e into elastic:main Jul 11, 2025
12 checks passed
@kibanamachine kibanamachine added the backport missing Added to PRs automatically when the are determined to be missing a backport. label Jul 15, 2025
@kibanamachine
Copy link
Copy Markdown
Contributor

Friendly reminder: Looks like this PR hasn’t been backported yet.
To create automatically backports add a backport:* label or prevent reminders by adding the backport:skip label.
You can also create backports manually by running node scripts/backport --pr 219278 locally
cc: @vitaliidm

@vitaliidm vitaliidm added backport:skip This PR does not require backporting and removed backport missing Added to PRs automatically when the are determined to be missing a backport. backport:version Backport to applied version labels labels Jul 15, 2025
kertal pushed a commit to kertal/kibana that referenced this pull request Jul 25, 2025
…cross multiple indices during ES|QL rule pagination requests (elastic#219278)

## Summary

- addresses elastic#216891
- follow up to elastic#217069
- accounts for index when excluding ids from subsequent pagination
requests. It will prevent situations when identical event ids present in
multiple indices and can be excluded when encountered first time for one
of the indices
- changes state from `excludedDocuments?: ExcludedDocument[];` to `
excludedDocuments?: Record<string, ExcludedDocument[]>;` to store
information of index. Where key is document index


###  Setup


<details>
<summary> Setup 2 indices with identical documents ids </summary>


```JSON

PUT close_alerts_1
PUT close_alerts_1/_mapping
{
  "properties": {
    "@timestamp": {
      "type": "date"
    },
    "agent": {
      "properties": {
        "name": {
          "type": "keyword"
        }
      }
    },
    "source": {
      "properties": {
        "ip": {
          "type": "ip"
        }
      }
    },
    "destination": {
      "properties": {
        "ip": {
          "type": "ip"
        },
        "port": {
          "type": "keyword"
        }
      }
    }
  }
}


PUT close_alerts_2
PUT close_alerts_2/_mapping
{
  "properties": {
    "@timestamp": {
      "type": "date"
    },
    "agent": {
      "properties": {
        "name": {
          "type": "keyword"
        }
      }
    },
    "source": {
      "properties": {
        "ip": {
          "type": "ip"
        }
      }
    },
    "destination": {
      "properties": {
        "ip": {
          "type": "ip"
        },
        "port": {
          "type": "keyword"
        }
      }
    }
  }
}


POST close_alerts_1/_doc/CFnnxZcBgU3wmL9Lp7xG
{
 "@timestamp": "2025-07-01T09:26:30.425Z",
 "source.ip": "127.0.0.1",
 "destination.ip": "127.0.0.1",
 "destination.port": 1,
 "agent.name": "test-0"
}

POST close_alerts_2/_doc/CFnnxZcBgU3wmL9Lp7xG
{
 "@timestamp": "2025-07-01T09:26:30.425Z",
 "source.ip": "127.0.0.1",
 "destination.ip": "127.0.0.1",
 "destination.port": 1,
 "agent.name": "test-0"
}

```

</details>

Exported rule [Test
rule](https://github.com/user-attachments/files/20998493/rules_export_identical_ids_pr.ndjson.zip)


### query before

```JSON

POST _query/async?drop_null_columns=true&allow_partial_results=true
{
  "query": "from close_alerts* METADATA _id, _index | limit 101",
  "filter": {
    "bool": {
      "filter": [
        {
          "range": {
            "@timestamp": {
              "lte": "2025-07-01T12:26:45.110Z",
              "gte": "2025-06-30T11:56:45.110Z",
              "format": "strict_date_optional_time"
            }
          }
        },
        {
          "bool": {
            "must": [],
            "filter": [],
            "should": [],
            "must_not": []
          }
        }
      ],
      "must_not": {
        "ids": {
          "values": [
            "CFnnxZcBgU3wmL9Lp7xG"
          ]
        }
      }
    }
  },
  "wait_for_completion_timeout": "4m",
  "keep_alive": "60s"
}

```

### query after

```JSON

POST _query/async?drop_null_columns=true&allow_partial_results=true
{
  "query": "from close_alerts* METADATA _id, _index | limit 101",
  "filter": {
    "bool": {
      "filter": [
        {
          "range": {
            "@timestamp": {
              "lte": "2025-07-01T12:27:57.472Z",
              "gte": "2025-06-30T11:57:57.472Z",
              "format": "strict_date_optional_time"
            }
          }
        },
        {
          "bool": {
            "must": [],
            "filter": [],
            "should": [],
            "must_not": []
          }
        }
      ],
      "must_not": [
        {
          "bool": {
            "filter": [
              {
                "ids": {
                  "values": [
                    "CFnnxZcBgU3wmL9Lp7xG"
                  ]
                }
              },
              {
                "term": {
                  "_index": "close_alerts_1"
                }
              }
            ]
          }
        },
        {
          "bool": {
            "filter": [
              {
                "ids": {
                  "values": [
                    "CFnnxZcBgU3wmL9Lp7xG"
                  ]
                }
              },
              {
                "term": {
                  "_index": "close_alerts_2"
                }
              }
            ]
          }
        }
      ]
    }
  },
  "wait_for_completion_timeout": "4m",
  "keep_alive": "60s"
}

```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport:skip This PR does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:Detection Engine Security Solution Detection Engine Area v9.2.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants