fix: Search for risk_level, search result is empty

This commit is contained in:
wangruidong
2025-11-25 15:52:58 +08:00
committed by 老广
parent fde19764e0
commit 96fdc025cd
2 changed files with 15 additions and 8 deletions

View File

@@ -2,6 +2,7 @@
#
import datetime
import inspect
import sys
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
@@ -334,6 +335,10 @@ class ES(object):
def is_keyword(props: dict, field: str) -> bool:
return props.get(field, {}).get("type", "keyword") == "keyword"
@staticmethod
def is_long(props: dict, field: str) -> bool:
return props.get(field, {}).get("type") == "long"
def get_query_body(self, **kwargs):
new_kwargs = {}
for k, v in kwargs.items():
@@ -361,10 +366,10 @@ class ES(object):
if index_in_field in kwargs:
index['values'] = kwargs[index_in_field]
mapping = self.es.indices.get_mapping(index=self.query_index)
mapping = self.es.indices.get_mapping(index=self.index)
props = (
mapping
.get(self.query_index, {})
.get(self.index, {})
.get('mappings', {})
.get('properties', {})
)
@@ -375,6 +380,9 @@ class ES(object):
if k in ("org_id", "session") and self.is_keyword(props, k):
exact[k] = v
elif self.is_long(props, k):
exact[k] = v
elif k in common_keyword_able:
exact[f"{k}.keyword"] = v

View File

@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
#
import pytz
from datetime import datetime
from common.utils import get_logger
from common.plugins.es import ES
import pytz
from common.plugins.es import ES
from common.utils import get_logger
logger = get_logger(__file__)
@@ -27,8 +26,8 @@ class CommandStore(ES):
"type": "long"
}
}
exact_fields = {}
fuzzy_fields = {'input', 'risk_level', 'user', 'asset', 'account'}
exact_fields = {'risk_level'}
fuzzy_fields = {'input', 'user', 'asset', 'account'}
match_fields = {'input'}
keyword_fields = {'session', 'org_id'}