1.问题描述

错误日志:

elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host='192.168.56.100', port=9200): Read timed out. (read timeout=10))

2.原因分析

ElasticSearch正常运行,在没有特别设置的情况下,timeout 的值是10s。

3.解决方法

普遍情况下有两种解决办法,推荐第1种,本人亲自在自己的环境中试过第二种,也是OK的。

方法一:在请求指令中设置过期时间,例如以下这种方式:

es.search(index="my_index",
          doc_type="document",
          body=get_req_body(),
          request_timeout=30)

方法二:在建立连接的请求URL中设置,例如以下这种方式:(本人是使用Python脚本向ElasticSearch中写入数据,这样设置OK)

es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30)
或
es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30, max_retries=10, retry_on_timeout=True)

参考博文:

Connection Timeout with Elasticsearch

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐