From 8a3acb649e1b00994dc33b2f18aa69fde5cb8014 Mon Sep 17 00:00:00 2001 From: feng <1304903146@qq.com> Date: Fri, 23 May 2025 19:04:31 +0800 Subject: [PATCH] fix: ES non-global organizations cannot be queried --- apps/common/plugins/es.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/common/plugins/es.py b/apps/common/plugins/es.py index 1e0d6efd2..76d678af5 100644 --- a/apps/common/plugins/es.py +++ b/apps/common/plugins/es.py @@ -340,8 +340,19 @@ 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) + props = ( + mapping + .get(self.query_index, {}) + .get('mappings', {}) + .get('properties', {}) + ) + org_id_type = props.get('org_id', {}).get('type', 'keyword') + for k, v in kwargs.items(): - if k in exact_fields.union(keyword_fields): + if k == 'org_id' and org_id_type == 'keyword': + exact[k] = v + elif k in exact_fields.union(keyword_fields): exact['{}.keyword'.format(k)] = v elif k in match_fields: match[k] = v