Skip to content

Fix/data stream delete support#1755

Merged
jertel merged 3 commits into
jertel:masterfrom
peterlehot:fix/data-stream-delete-support
Apr 7, 2026
Merged

Fix/data stream delete support#1755
jertel merged 3 commits into
jertel:masterfrom
peterlehot:fix/data-stream-delete-support

Conversation

@peterlehot
Copy link
Copy Markdown
Contributor

Description

Replace es.delete() with delete_by_query() in aggregation cleanup (send_pending_alerts and
add_aggregated_alert) to support Elasticsearch data streams as the writeback index.

Elasticsearch data streams do not support single-document DELETE operations (es.delete()), which
causes aggregation cleanup to fail with an error. The delete_by_query API works on data streams and
is functionally equivalent for this use case.

Checklist

  • I have reviewed the contributing guidelines.
  • I have included unit tests for my changes or additions.
  • I have successfully run make test-docker with my changes.
  • I have manually tested all relevant modes of the change in this PR.
  • I have updated the documentation. -> not applicable, no user-facing changes
  • I have updated the changelog.

Questions or Comments

  • Documentation update is not applicable - this is an internal behavior change with no new
    configuration options or user-facing API changes.
  • The 2 test failures in make test-docker (test_tencentsms_alert_secret_id_error,
    test_twilio_rest_exception) are pre-existing and unrelated to this change.
  • Manually tested with ElastAlert2 using an Elasticsearch data stream as the writeback index -
    aggregation alerts are now correctly cleaned up after being sent.

peterlehot and others added 2 commits April 1, 2026 10:27
Elasticsearch data streams do not support single-document DELETE
operations. When ElastAlert2 uses a data stream as the writeback
index, aggregation cleanup fails because es.delete() returns 404.

This replaces two es.delete() calls in elastalert.py with
es.delete_by_query() using a term query on _id, which is supported
on data streams while maintaining the same behavior for regular
indices.

Affected methods:
- send_pending_alerts(): cleanup after sending scheduled aggregation
- get_aggregated_matches(): cleanup after collecting aggregated matches

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add delete_by_query to mock_es_client to fix 4 test failures caused
  by the es.delete() → delete_by_query() change
- Add CHANGELOG entry for the data stream fix

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@jertel
Copy link
Copy Markdown
Owner

jertel commented Apr 1, 2026

Thanks for the submission. Are you manually creating the data streams? And did you confirm that the delete_by_query() invocation worked (correctly deleted) the documents when using the standard index rather than data stream?

@peterlehot
Copy link
Copy Markdown
Contributor Author

peterlehot commented Apr 2, 2026 via email

@peterlehot
Copy link
Copy Markdown
Contributor Author

Hi Jason,

i tested suggested changes for compatibility and i do not see any problems. See attached protocol

test-protocol.md

@jertel jertel merged commit 2e17fa6 into jertel:master Apr 7, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants