Elasticsearch 连接超时

2024-03-19

from datetime import datetime
from elasticsearch import Elasticsearch
es = Elasticsearch()

doc = {
    'author': 'kimchy',
    'text': 'Elasticsearch: cool. bonsai cool.',
    'timestamp': datetime(2010, 10, 10, 10, 10, 10)
}
res = es.index(index="test-index", doc_type='tweet', id=1, body=doc)
print(res['created'])

这个简单的代码返回以下错误:

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

很奇怪,因为服务器已经准备好并设置好了(http://本地主机:9200/ http://localhost:9200/返回一些 json)。


默认情况下,超时值设置为 10 秒。如果想更改全局超时值,可以通过设置标志来实现超时=你的时间创建对象时。

如果您已经创建了对象而没有指定超时值,那么您可以使用以下方法为特定请求设置超时值request_timeout=您的时间查询中的标志。

es.search(index="my_index",
          doc_type="document",
          body=get_req_body(),
          request_timeout=30)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Elasticsearch 连接超时 的相关文章

随机推荐