diff --git a/apps/common/plugins/es.py b/apps/common/plugins/es.py index 376bdd98b..ab18df5de 100644 --- a/apps/common/plugins/es.py +++ b/apps/common/plugins/es.py @@ -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 diff --git a/apps/terminal/backends/command/es.py b/apps/terminal/backends/command/es.py index e7e8a7975..0c53461ab 100644 --- a/apps/terminal/backends/command/es.py +++ b/apps/terminal/backends/command/es.py @@ -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'}