TypeError: __init__() got an unexpected keyword argument ‘transport_options‘

在较新版本的 Elasticsearch Python 客户端中,确实没有名为 transport_options 的参数。要设置传输选项,需要使用 transport_class 参数来创建自定义传输类,并在传输类中设置选项。

以下是一个示例,展示如何创建自定义传输类以设置传输选项:

python 复制代码
from elasticsearch import Elasticsearch, Transport
from elasticsearch.connection import RequestsHttpConnection

# 创建自定义传输类
class CustomTransport(Transport):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 设置传输选项
        self.max_retries = 3  # 例如,设置最大重试次数
        self.retry_on_timeout = True  # 设置超时时是否重试

# 创建 Elasticsearch 客户端并使用自定义传输类
es = Elasticsearch(
    hosts=['http://localhost:9200'],  # 替换为您的 Elasticsearch 主机地址和端口
    transport_class=CustomTransport
)

# 使用 create 方法创建索引
try:
    result = es.indices.create(index='news', ignore=400)
    print(result)
except Exception as e:
    print(f"An error occurred: {e}")

在这个示例中,我们创建了一个名为 CustomTransport 的自定义传输类,并在其中设置了传输选项。然后,我们在初始化 Elasticsearch 客户端时,通过 transport_class 参数传递了这个自定义传输类。

请根据您的需求来调整传输选项的设置,并确保在自定义传输类中进行适当的配置。这样,您可以自定义传输行为以满足您的要求。

相关推荐
Elastic 中国社区官方博客7 分钟前
5 分钟内将 56 页扫描文档转化为带引用的答案:面向搜索无法读取的文档的检索增强生成流水线
大数据·运维·人工智能·elasticsearch·搜索引擎·信息可视化·全文检索
深蓝电商API1 小时前
从爬虫到Agent:数据采集的下一个形态是什么
爬虫
xiangjiaodalishi1 小时前
主流 AI 爬虫 User-Agent 清单大全:分组、配置与持续维护(2026 版)
人工智能·爬虫·python
深蓝电商API1 天前
用向量数据库存储爬取内容:语义检索的高级玩法
爬虫·向量数据库
深蓝电商API1 天前
Playwright+多模态大模型:让AI自己“看”页面并决策
人工智能·爬虫·playwright
Elasticsearch1 天前
5 分钟内将 56 页扫描文档转化为带引用的答案:面向搜索无法读取的文档的检索增强生成流水线
elasticsearch
远航计算机1 天前
收录从分钟级变 3 到 7 天,抢首发为什么失效了
大数据·人工智能·爬虫·chatgpt·aigc·1024程序员节
core5122 天前
Elasticsearch 车牌号片段搜索:n-gram 倒排索引实战方案
elasticsearch·n-gram·索引·倒排索引·号牌·片段
এ慕ོ冬℘゜2 天前
ES Promise.all/ Promise.race
前端·javascript·elasticsearch
Sayai2 天前
Elasticsearch 日志写入链路调优实战:ingest pipeline 补时间戳、时区偏移修复与按值类型路由(附 translog 实测)
大数据·运维·elasticsearch·搜索引擎·性能优化