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