我正在尝试使用elasticsearch_dsl
为特定请求设置timeout
。 我已经尝试了以下方法:
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, F
...
def do_stuff(self, ids):
client = Elasticsearch(['localhost'], timeout=30)
s = Search(using=client,
index= 'my_index',
doc_type=['my_type'])
s = s[0:100]
f = F('terms', my_field=list(ids))
s.filter(f)
response = s.execute()
return response.hits.hits
注:
- 当我将
doc_type
更改为包含一百万个实体的类型时,查询运行良好。 - 当我将
doc_type
指向数十亿个实体时,会出现超时错误,显示默认的10秒超时。
从 elasticsearch_dsl
文档 中,我甚至尝试设置默认连接超时时间:
from elasticsearch import Elasticsearch
from elasticsearch_dsl import Search, F
from elasticsearch_dsl import connections
connections.connections.create_connection(hosts=['localhost'], timeout=30)
我仍然收到了10秒超时错误。
TransportError(400, 'parse_exception', 'Failed to parse setting [timeout] with value [30] as a time value: unit is missing or unrecognized')
。您应该使用 request_timeout=30 代替。 - coda