Python 弹性搜索异常连接错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25471828/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
elasticsearch exceptions ConnectionError
提问by Deepti
I am making a Django app. It uses Haystack with elasticsearch as backend.
我正在制作一个 Django 应用程序。它使用 Haystack 和 elasticsearch 作为后端。
When I run
当我跑
./manage.py rebuild_index
I get this error:
我收到此错误:
aborted.', error(61, 'Connection refused'))) caused by: ProtocolError(('Connection aborted.', error(61, 'Connection refused')))
aborted.', error(61, 'Connection denied'))) 引起: ProtocolError(('Connection aborted.', error(61, 'Connection denied')))
What could have caused this?
这可能是什么原因造成的?
The log:
日志:
./manage.py rebuild_index
No handlers could be found for logger "django_facebook.models"
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
Failed to clear Elasticsearch index: ConnectionError(('Connection aborted.', error(61, 'Connection refused'))) caused by: ProtocolError(('Connection aborted.', error(61, 'Connection refused')))
All documents removed.
Indexing 4 restos
ERROR:root:Error updating litchee using default
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
self.update_backend(label, using)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 266, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
backend.update(index, current_qs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 184, in update
bulk_index(self.conn, prepped_docs, index=self.index_name, doc_type='modelresult')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 145, in bulk
for ok, item in streaming_bulk(client, actions, **kwargs):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 104, in streaming_bulk
resp = client.bulk(bulk_actions, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped
return func(*args, params=params, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 646, in bulk
params=params, body=self._bulk_body(body))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/transport.py", line 284, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 51, in perform_request
raise ConnectionError('N/A', str(e), e)
ConnectionError: ConnectionError(('Connection aborted.', error(61, 'Connection refused'))) caused by: ProtocolError(('Connection aborted.', error(61, 'Connection refused')))
Traceback (most recent call last):
File "./manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
utility.execute()
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/rebuild_index.py", line 16, in handle
call_command('update_index', **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/__init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
output = self.handle(*args, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 195, in handle
return super(Command, self).handle(*items, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/core/management/base.py", line 385, in handle
label_output = self.handle_label(label, **options)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 221, in handle_label
self.update_backend(label, using)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 266, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 89, in do_update
backend.update(index, current_qs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 184, in update
bulk_index(self.conn, prepped_docs, index=self.index_name, doc_type='modelresult')
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 145, in bulk
for ok, item in streaming_bulk(client, actions, **kwargs):
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/helpers/__init__.py", line 104, in streaming_bulk
resp = client.bulk(bulk_actions, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 68, in _wrapped
return func(*args, params=params, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 646, in bulk
params=params, body=self._bulk_body(body))
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/transport.py", line 284, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 51, in perform_request
raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(('Connection aborted.', error(61, 'Connection refused'))) caused by: ProtocolError(('Connection aborted.', error(61, 'Connection refused')))
Running bin/elasticsearch gives this:
运行 bin/elasticsearch 给出了这个:
[2014-08-25 17:53:38,901][INFO ][node ] [Arize] version[1.3.1], pid[1781], build[2de6dc5/2014-07-28T14:45:15Z]
[2014-08-25 17:53:38,902][INFO ][node ] [Arize] initializing ...
[2014-08-25 17:53:38,976][INFO ][plugins ] [Arize] loaded [], sites []
[2014-08-25 17:53:54,722][INFO ][node ] [Arize] initialized
[2014-08-25 17:53:54,734][INFO ][node ] [Arize] starting ...
[2014-08-25 17:53:56,131][INFO ][transport ] [Arize] bound_address {inet[/0:0:0:0:0:0:0:0:9300]}, publish_address {inet[/192.168.1.83:9300]}
[2014-08-25 17:53:57,168][INFO ][discovery ] [Arize] elasticsearch/uWwljr09R0-hZ1-5eH4NlQ
[2014-08-25 17:54:00,714][INFO ][cluster.service ] [Arize] new_master [Arize][uWwljr09R0-hZ1-5eH4NlQ][deeptis-mbp.local.lan][inet[/192.168.1.83:9300]], reason: zen-disco-join (elected_as_master)
[2014-08-25 17:54:00,987][INFO ][http ] [Arize] bound_address {inet[/0:0:0:0:0:0:0:0:9200]}, publish_address {inet[/192.168.1.83:9200]}
[2014-08-25 17:54:00,988][INFO ][node ] [Arize] started
[2014-08-25 17:54:01,337][INFO ][gateway ] [Arize] recovered [0] indices into cluster_state
But on running ps -A elasticsearch does not show up as a running process.
但是在运行 ps -A elasticsearch 时不会显示为正在运行的进程。
What am I doing wrong?
我究竟做错了什么?
采纳答案by Anton
Connection refused means just that, that the TCP connection to the Elasticsearch HTTP service was refused. The reason can be a number of things, for instance that you are using the wrong host or port for the HTTP endpoint, or that the elasticsearch node is not running for some reason.
连接被拒绝只是意味着,到 Elasticsearch HTTP 服务的 TCP 连接被拒绝。原因可能有很多,例如您为 HTTP 端点使用了错误的主机或端口,或者 elasticsearch 节点由于某种原因没有运行。
Before you try to use Haystack, test that elasticsearch works by issuing a direct HTTP request with something like:
在您尝试使用 Haystack 之前,请通过发出类似以下内容的直接 HTTP 请求来测试 elasticsearch 是否工作:
curl -X GET http://192.168.77.88:9200/_cat/indices
Where 192.168.77.88is the IP address of your elasticsearch node, and 9200is the TCP port. When that succeeds, check and double check that you have the same URL configuration in you Haystack config.
192.168.77.88你的elasticsearch节点的IP地址在哪里,9200是TCP端口。如果成功,请检查并仔细检查您在 Haystack 配置中是否具有相同的 URL 配置。
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://192.168.77.88:9200/',
'INDEX_NAME': 'haystack',
},
}
回答by ganga
I had the same problem. Just got it resolved by actually running the Elasticsearch on port 9200. If you are on windows, goto the bin directory of Elasticsearch installation and run the batch file of whichever Elasticsearch version you are using.
我有同样的问题。刚刚通过在端口 9200 上实际运行 Elasticsearch 解决了它。如果您在 Windows 上,请转到 Elasticsearch 安装的 bin 目录并运行您使用的任何 Elasticsearch 版本的批处理文件。

