From 6dae2f895c7e3d7b68d96e1042b2fd90252926ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=96=87=E8=89=B3?= Date: Sun, 16 Aug 2026 22:35:53 +0800 Subject: [PATCH] fix: add immediate elasticsearch compatibility hotfix to del_comm.py --- dags/business/business/community/del_comm.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/dags/business/business/community/del_comm.py b/dags/business/business/community/del_comm.py index bd95a47..7020187 100644 --- a/dags/business/business/community/del_comm.py +++ b/dags/business/business/community/del_comm.py @@ -1,6 +1,22 @@ """ 同步删除小区基本信息至ES206 """ +# 兼容性补丁:解决 Elasticsearch 8.x/9.x 客户端在老版本 ES 集群上因 compatible-with 头部导致的 ApiError(406) +try: + import elasticsearch + ver = getattr(elasticsearch, '__version__', None) + if ver and not str(ver).startswith('7.'): + original_init = elasticsearch.Elasticsearch.__init__ + def patched_init(self, *args, **kwargs): + headers = kwargs.get('headers', {}) + headers['Accept'] = 'application/json' + headers['Content-Type'] = 'application/json' + kwargs['headers'] = headers + original_init(self, *args, **kwargs) + elasticsearch.Elasticsearch.__init__ = patched_init +except Exception: + pass + import logging import pandas as pd from goojia_utils import MAIN_MONGO_CLIENT, ElasticSearchClient, commutils, dateutils, ClickHouseClient