如何修复Elasticsearch中的读取超时

Hen*_*min 29 timeout timeoutexception connection-timeout executiontimeout elasticsearch

我使用Elasticsearch-1.1.0来索引推文.索引过程没问题.然后我升级了版本.现在我使用Elasticsearch-1.3.2,我随机收到这条消息:

Exception happened: Error raised when there was an exception while talking to ES.
ConnectionError(HTTPConnectionPool(host='127.0.0.1', port=8001): Read timed out. (read timeout=10)) caused by: ReadTimeoutError(HTTPConnectionPool(host='127.0.0.1', port=8001): Read timed out. (read timeout=10)).
Run Code Online (Sandbox Code Playgroud)

随机快照:

Happened --33s-- Happened --27s-- Happened --22s-- Happened --10s-- Happened --39s-- Happened --25s-- Happened --36s-- Happened --38s-- Happened --19s-- Happened --09s-- Happened --33s-- Happened --16s-- Happened 

--XXs-- = after XX seconds
Run Code Online (Sandbox Code Playgroud)

有人可以指出如何解决Read timed out问题吗?

非常感谢你.

Ski*_*hie 29

由于您看到的错误可能与您正在使用的客户有关,因此很难给出直接答案.但是,解决方案可能是以下之一:

1.通过传递timeout参数创建ES客户端时,全局增加默认超时.Python中的示例

es = Elasticsearch(timeout=30)
Run Code Online (Sandbox Code Playgroud)

2.设置客户端每个请求的超时时间.摘自下面的Elasticsearch Python文档.

# only wait for 1 second, regardless of the client's default
es.cluster.health(wait_for_status='yellow', request_timeout=1)
Run Code Online (Sandbox Code Playgroud)

以上将为集群提供一些额外的响应时间

  • 是否有关于根本原因的新问题?我看到了同样的问题,我想知道弹性搜索需要很长时间才能做出回应的根本原因是什么. (3认同)

Ami*_*ini 21

试试这个:

es = Elasticsearch(timeout=30, max_retries=10, retry_on_timeout=True)
Run Code Online (Sandbox Code Playgroud)

它可能不会完全避免ReadTimeoutError,但它会使它们最小化.


vly*_*bin 6

当查询大小很大时,也可能会发生读取超时。例如,在我的 ES 索引大小相当大(> 3M 文档)的情况下,搜索包含 30 个单词的查询大约需要 2 秒,而搜索包含 400 个单词的查询则需要超过 18 秒。因此,对于足够大的查询,甚至timeout=30无法拯救您。一个简单的解决方案是将查询裁剪为可以在超时以下回答的大小。


Dou*_*oug 5

对于它的价值,我发现这似乎与损坏的索引状态有关。

很难可靠地重现这个问题,但我已经见过好几次了;操作正常运行,除了某些似乎定期挂起 ES 的操作(特别是似乎刷新索引)。

删除索引 ( curl -XDELETE http://localhost:9200/foo) 并从头开始重新索引为我解决了这个问题。

如果您看到这种行为,我建议定期清除和重新索引。

  • 这太昂贵了,除非你只有小数据。 (4认同)