我正在尝试使用带有Elasticsearch的Python从索引中读取文档。我收到找不到解决方案的错误。有谁知道我该如何解决?
我一直在网上寻找同样的问题,但是找不到任何相关的文章/解决方案。
这是我的代码:
from elasticsearch import Elasticsearch
from pandasticsearch import Select
# Connection to ElasticSearch
es = Elasticsearch(['http://localhost:9200'],timeout=600)
# Retrieving all documents in index (no query given)
documents = es.search(index='myindex',body={"query": {"match_all": {}}})
# Convert the result to Pandas Dataframe
pandas_df = Select.from_dict(documents).to_pandas()
我得到的错误是:
GET http://localhost:9200/myindex/_search [status:503 request:0.062s]
GET http://localhost:9200/myindex/_search [status:503 request:0.027s]
GET http://localhost:9200/myindex/_search [status:503 request:0.030s]
GET http://localhost:9200/myindex/_search [status:503 request:0.017s]
Traceback (most recent call last):
File "<ipython-input-6-68e07be7c100>", line 1, in <module>
documents = es.search(index='myindex',body={"query": {"match_all": {}}})
File "C:\Users\XXXXXX\AppData\Local\Continuum\anaconda3\lib\site-
packages\elasticsearch\client\utils.py", line 76, in _wrapped
return func(*args, params=params, **kwargs)
File "C:\Users\XXXXXX\AppData\Local\Continuum\anaconda3\lib\site-
packages\elasticsearch\client\__init__.py", line 655, in search
doc_type, '_search'), params=params, body=body)
File "C:\Users\XXXXXX\AppData\Local\Continuum\anaconda3\lib\site-
packages\elasticsearch\transport.py", line 318, in perform_request
status, headers_response, data = connection.perform_request(method, url,
params, body, headers=headers, ignore=ignore, timeout=timeout)
File "C:\Users\XXXXXX\AppData\Local\Continuum\anaconda3\lib\site-
packages\elasticsearch\connection\http_urllib3.py", line 185, in
perform_request
self._raise_error(response.status, raw_data)
File "C:\Users\XXXXXX\AppData\Local\Continuum\anaconda3\lib\site-
packages\elasticsearch\connection\base.py", line 125, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code,
error_message, additional_info)
TransportError: TransportError(503, 'search_phase_execution_exception')
这是elasticsearch日志:
[2019-04-25T11:19:35,843] [DEBUG] [o.e.a.s.TransportSearchAction] [Cx6mYd6]所有分片在以下阶段均失败:[查询] [2019-04-25T11:19:35,845] [WARN] [r.suppressed] [Cx6mYd6]路径:/ myindex / _search,参数:{index = myindex} org.elasticsearch.action.search.SearchPhaseExecutionException:所有分片均失败 在org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseFailure(AbstractSearchAsyncAction.java:293)〜[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.action.search.AbstractSearchAsyncAction.executeNextPhase(AbstractSearchAsyncAction.java:133)〜[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.action.search.AbstractSearchAsyncAction.onPhaseDone(AbstractSearchAsyncAction.java:254)〜[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.action.search.InitialSearchPhase.onShardFailure(InitialSearchPhase.java:101)〜[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.action.search.InitialSearchPhase.lambda $ performPhaseOnShard $ 1(InitialSearchPhase.java:209)〜[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.action.search.InitialSearchPhase $ 1.doRun(InitialSearchPhase.java:188)[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.common.util.concurrent.ThreadContext $ ContextPreservingAbstractRunnable.doRun(ThreadContext.java:759)[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.common.util.concurrent.TimedRunnable.doRun(TimedRunnable.java:41)[elasticsearch-6.6.1.jar:6.6.1] 在org.elasticsearch.common.util.concurrent.AbstractRunnable.run(AbstractRunnable.java:37)[elasticsearch-6.6.1.jar:6.6.1] 在java.util.concurrent.ThreadPoolExecutor.runWorker(未知来源)[?: 1.8.0_181] 在java.util.concurrent.ThreadPoolExecutor $ Worker.run(未知来源)[?: 1.8.0_181] 在java.lang.Thread.run(未知来源)[?: 1.8.0_181]
有人知道如何解决此问题吗?
答案 0 :(得分:0)
我在启动 elasticsearch
服务后立即发送请求时遇到此错误。几秒钟后,我重试并成功执行了请求。