Python Elasticsearch连接超时
此simples代码返回以下错误:Python Elasticsearch连接超时,python,python-2.7,
elasticsearch,Python,Python 2.7,
elasticsearch,此simples代码返回以下错误: 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 =
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'])
非常奇怪,因为服务器已准备就绪并已设置(正在返回一些json)。
res=es.index(index=“test index”,doc_type='tweet',id=1,body=doc,timeout=30)
默认情况下,超时值设置为10秒。如果要更改全局超时值,可以在创建对象时设置标志timeout=your time
如果已经创建了对象,但没有指定超时值,则可以使用查询中的request\u timeout=your time标志为特定请求设置超时值
elasticsearch.exceptions.ConnectionTimeout: ConnectionTimeout caused by - ReadTimeoutError(HTTPConnectionPool(host='localhost', port=9200): Read timed out. (read timeout=10))
如果您使用的是Amazon弹性搜索服务,则可能会出现连接超时问题
es.search(index="my_index",
doc_type="document",
body=get_req_body(),
request_timeout=30)
上面的python代码将默认端口从9200覆盖到443,并将SSL设置为true,这将解决问题
如果未指定端口,则它正在尝试连接到指定主机中的端口9200,并在超时后失败这与将超时时间增加到30秒无关。 人们真的认为弹性搜索最多需要30秒才能返回一个微小的点击吗 我解决这个问题的方法是转到config/elasticsearch.yml 取消对以下内容的注释
es = Elasticsearch([{'host': 'xxxxxx.us-east-1.es.amazonaws.com', 'port': 443, 'use_ssl': True}])
Network.host可能设置为192.168.0.1,这可能会起作用,但我刚刚将其更改为“localhost”我的个人问题已通过
解决(超时=10000)
几乎从未访问过,因为服务器上的条目只有7.000个,但流量很大,资源被占用,这就是连接中断的原因。请注意,执行es.search
(或es.index
)时超时的常见原因之一是查询量大。例如,在我的ES索引非常大(>3M个文档)的情况下,搜索30个单词的查询大约需要2秒,而搜索400个单词的查询则需要18秒。因此,对于一个足够大的查询,即使timeout=30也不能节省您的时间。一个简单的解决方案是将查询裁剪到可以在超时以下回答的大小
如果原因是流量,增加超时或在超时时重试将对您有所帮助,否则这可能是您的罪魁祸首。两个选项有帮助:
1:增加超时时间
设置超时为我解决了这个问题。请注意,较新版本需要一个单元,例如timeout=“60s”
:
es.index(index=index\u name,doc\u type=“domains”,id=domain.id,body=body,timeout=“60s”)
如果没有单位,例如通过设置timeout=60
,您将得到
http.port: 9200
network.host: 'localhost'
2:减少文本长度
它还有助于减少文本长度,例如通过剪切长文本,因此elastic可以更快地存储文本,从而避免超时:
elasticsearch.exceptions.RequestError: RequestError(400, 'illegal_argument_exception', 'failed to parse setting [timeout] with value [60] as a time value: unit is missing or unrecognized')
尝试在Elasticsearch初始化中设置超时:
es.index(index=index_name, doc_type="domains", id=domain.id, body=text[:5000], timeout="60s")
您甚至可以将retry\u on\u timeout
设置为True
,并为max\u retries
提供一个可选数字:
es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30)
超时的原因可能很多,似乎值得检查elasticsearch端的日志(
logs/elasticsearch.log
)以查看详细错误。在我们的案例中,ES上的错误是:
es = Elasticsearch([{'host': HOST_ADDRESS, 'port': THE_PORT}], timeout=30, max_retries=10, retry_on_timeout=True)
如本文所述,这是因为我们的磁盘已满。我们在一天前调整了它(和分区)的大小以解决这个问题,但是如果高/低水印被击中一次(我们在5.5.x上),ES需要重新启动,而我们没有这样做
只需在生产时重新启动ES就解决了这个问题。我在ubuntu的端口9202(9200正被
elasticsearch 6
使用)尝试elasticsearch 7.11.1
(使用apt安装
)时遇到了这个超时问题
我在谷歌上搜索了将近两个小时,最后才把它修好。原来我需要在/etc/elasticsearch/elasticserch.yml
primary shard is not active Timeout: [1m]
我希望这可能会对某人有所帮助。扩展requestTimeout
如果服务器太忙,是的,您只需点击一次就可能出现此错误。或者,如果DNS解析出现问题,则超时的原因很多。是否可以将此设置为60?即使设置了超时,我也会超时30@Kishan你的文档有多大?嗨,@RohitPatwa我的问题是通过缩短文档的长度来解决的。我不记得现在尸体有多大了。感谢您的帮助:)如果我的老板不让我更改超时,并且它在一条记录上失败了怎么办?或者您可以使用端口80 es=Elasticsearch([{'host':'xxxxxx.us-east-1.es.amazonaws.com','port':80}]),这将不起作用,因为错误仍然存在,将超时值声明为10
cluster.initial_master_nodes: ["node-1"] # earlier in the same file: node.name: node-1
client = new elasticsearch.Client({
host : 'http://localhost:9200',
requestTimeout: 60000
});