Skip to content

[FR] Updates to KQL Lib Parsing #3605

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/kql/kql/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .kql2eql import KqlToEQL
from .parser import lark_parse, KqlParser

__version__ = '0.1.7'
__version__ = '0.1.8'
__all__ = (
"ast",
"from_eql",
Expand Down
5 changes: 3 additions & 2 deletions lib/kql/kql/dsl.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ def boolean(**kwargs):
elif boolean_type == "must_not" and len(children) == 1:
# must_not: [{bool: {must: x}}] -> {must_not: x}
child = children[0]
if list(child) == ["bool"] and list(child["bool"]) in (["filter"], ["must"]):
if list(child) == ["bool"] and list(child["bool"]) in (["filter"], ["must"]) and \
(len(child.get("bool", {}).get("filter", 1)) == 1 and len(child.get("bool", {}).get("must", 1)) == 1):
negated, = child["bool"].values()
dsl = {"must_not": negated}
else:
Expand All @@ -73,7 +74,7 @@ def _walk_exists(self, _):
return lambda field: {"exists": {"field": field}}

def _walk_wildcard(self, tree):
return lambda field: {"query_string": {"fields": [field], "query": tree.value}}
return lambda field: {"wildcard": {field: { "value": tree.value}}}

def _walk_value(self, tree):
return lambda field: {"match": {field: tree.value}}
Expand Down
2 changes: 1 addition & 1 deletion lib/kql/pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "detection-rules-kql"
version = "0.1.7"
version = "0.1.8"
description = "Kibana Query Language parser for Elastic Detection Rules"
license = {text = "Elastic License v2"}
keywords = ["Elastic", "sour", "Detection Rules", "Security", "Elasticsearch", "kql"]
Expand Down
Loading