Skip to content

Commit 7455d58

Browse files
authored
feat: ✨ Add exists modifer for lucene (#117)
1 parent cfd2ecf commit 7455d58

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

sigma/backends/elasticsearch/elasticsearch_lucene.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ class LuceneBackend(TextQueryBackend):
134134
# List element separator
135135
list_separator: ClassVar[str] = " OR "
136136

137+
# Check if a field exists in the log not the value
138+
field_exists_expression: ClassVar[str] = "_exists_:{field}"
139+
field_not_exists_expression: ClassVar[str] = "NOT _exists_:{field}"
140+
137141
# Value not bound to a field
138142
# Expression for string value not bound to a field as format string with placeholder {value}
139143
unbound_value_str_expression: ClassVar[str] = "*{value}*"

tests/test_backend_elasticsearch_lucene.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -484,6 +484,26 @@ def test_lucene_windash_contains(lucene_backend: LuceneBackend):
484484
]
485485
)
486486

487+
def test_elasticsearch_exists(lucene_backend: LuceneBackend):
488+
assert (
489+
lucene_backend.convert(
490+
SigmaCollection.from_yaml(
491+
"""
492+
title: Test
493+
status: test
494+
logsource:
495+
category: test_category
496+
product: test_product
497+
detection:
498+
sel:
499+
fieldA|exists: yes
500+
fieldB|exists: no
501+
condition: sel
502+
"""
503+
)
504+
)
505+
== ['_exists_:fieldA AND NOT _exists_:fieldB']
506+
)
487507

488508
def test_lucene_reference_query(lucene_backend: LuceneBackend):
489509
with pytest.raises(

0 commit comments

Comments
 (0)