使用弹性搜索python包时出现读取超时错误
我已经安装了使用弹性搜索python包时出现读取超时错误,python,
elasticsearch,Python,
elasticsearch,我已经安装了elasticsearchpython包,并创建了一个elasticcluster。我正在使用以下python代码将数据发送到弹性云: from elasticsearch import Elasticsearch, RequestsHttpConnection import time import datetime es = Elasticsearch(['70.19.172.110:9200'],http_auth=('<username>','<passwo
elasticsearch
python包,并创建了一个elasticcluster。我正在使用以下python代码将数据发送到弹性云:
from elasticsearch import Elasticsearch, RequestsHttpConnection
import time
import datetime
es = Elasticsearch(['70.19.172.110:9200'],http_auth=('<username>','<password>'))
for x in range(0,5):
es.index(index='test', doc_type='json', id=x, body={
'data1':"Hello World',
'value':325,
'time': datetime.datetime.now()
})
print("Data sent {} ".format(x))
time.sleep(60)
从elasticsearch导入elasticsearch,请求shttpConnection
导入时间
导入日期时间
es=Elasticsearch(['70.19.172.110:9200'],http_auth=(''))
对于范围(0,5)内的x:
索引(index='test',doc_type='json',id=x,body={
'数据1':“你好,世界”,
“值”:325,
“时间”:datetime.datetime.now()
})
打印(“数据发送{}”。格式(x))
时间。睡眠(60)
正如你在代码中所看到的,我以1min时间间隔发送数据。sleep(60)
。这很好,所有5个数据都在elasticsearch中。然后我将时间。sleep(60)
更改为时间。sleep(300)
,它给了我以下错误:
elasticsearch.exceptions.ConnectionTimeout:ConnectionTimeout由-ReadTimeoutError引起(HTTPConnectionPool(host='70.19.172.110',port=9200):读取超时(读取超时=10))
有没有什么我做错了。有没有什么方法可以让我保持与elasticsearch的连接,这样我就不会犯这些类型的错误
谢谢。尝试增加es.index的超时时间,因为Elasticsearch的超时时间限制为10秒,如果在30秒时它将不响应,这意味着您的主机无法连接或不响应请求
from elasticsearch import Elasticsearch, RequestsHttpConnection
import time
import datetime
timenow = datetime.datetime.now()
es = Elasticsearch(['70.19.172.110:9200'],http_auth=('<username>','<password>'))
for x in range(0,5):
es.index(index='test', doc_type='json', id=x, body={
'data1':"Hello World",
'value':325,
'time':timenow,
'timeout':30, # The Time Of timeout you want
})
print("Data sent {} ".format(x))
time.sleep(60)
从elasticsearch导入elasticsearch,请求shttpConnection
导入时间
导入日期时间
timenow=datetime.datetime.now()
es=Elasticsearch(['70.19.172.110:9200'],http_auth=(''))
对于范围(0,5)内的x:
索引(index='test',doc_type='json',id=x,body={
“数据1”:“你好,世界”,
“值”:325,
“时间”:时间现在,
“超时”:30,#您想要的超时时间
})
打印(“数据发送{}”。格式(x))
时间。睡眠(60)
由于Elasticsearch的默认超时为10秒,因此您的连接不会重新访问主机,在Elasticsearch关闭主机连接之前,您有10秒的时间连接到主机Timeout@SkillerDz谢谢,所以你的意思是说我必须做es=Elasticsearch(['70.19.172.110:9200'],http_auth=(''))
每次我发送数据时。但是当我使用60秒时,它是如何工作的。?es.index(index='test',doc_type='json',id=x,body={'data1':“Hello World”,“value':325',time':datetime.datetime.now()'timeout':30#超时时间})您必须为es上的超时添加一个新值。index@SkillerDz我不明白。你的意思是,对于5分钟的超时,我必须加300作为超时值。你能解释一下这个问题吗,这样我也可以接受它我添加了“超时”:300
,但它仍然抛出相同的错误我用Ip我的路由器192.168.1.1:80和端口80尝试了这个脚本,这个脚本对我很好,我想问题出在你试图联系的主机上,可能端口9200已关闭,请尝试其他端口