mirror of
https://github.com/jumpserver/jumpserver.git
synced 2026-03-18 11:02:09 +00:00
fix: Search for risk_level, search result is empty
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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'}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user