elasticsearch 不能rebuild_index

elasticsearch can not rebuild_index

我想使用 haystack + elasticsearch

所以我安装elasticsearch

$ brew info elasticsearch

elasticsearch: stable 5.0.1, HEAD
Distributed search & analytics engine
https://www.elastic.co/products/elasticsearch
/usr/local/Cellar/elasticsearch/5.0.1 (98 files, 34.8M) *
  Built from source on 2016-11-29 at 17:52:15
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/elasticsearch.rb
==> Requirements
Required: java >= 1.8 ✔
==> Caveats
Data:    /usr/local/var/elasticsearch/elasticsearch_hanminsoo/
Logs:    /usr/local/var/log/elasticsearch/elasticsearch_hanminsoo.log
Plugins: /usr/local/Cellar/elasticsearch/5.0.1/libexec/plugins/
Config:  /usr/local/etc/elasticsearch/
plugin script: /usr/local/Cellar/elasticsearch/5.0.1/libexec/bin/plugin

To have launchd start elasticsearch now and restart at login:
  brew services start elasticsearch
Or, if you don't want/need a background service you can just run:
  elasticsearch

然后我启动 elasticsearch

$ brew services start elasticsearch

==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Counting objects: 10, done.
remote: Compressing objects: 100% (7/7), done.
remote: Total 10 (delta 0), reused 6 (delta 0), pack-reused 0
Unpacking objects: 100% (10/10), done.
Checking connectivity... done.
Tapped 0 formulae (36 files, 47K)
==> Successfully started `elasticsearch` (label: homebrew.mxcl.elasticsearch)

我想重建我的索引

$ python manage.py rebuild_index

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.
DELETE http://127.0.0.1:9200/haystack [status:N/A request:0.002s

[...]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/hanminsoo/.pyenv/versions/spec/lib/python3.5/site-packages/haystack/backends/elasticsearch_backend.py", line 231, in clear
self.conn.indices.delete(index=self.index_name, ignore=404)
  File "/Users/hanminsoo/.pyenv/versions/spec/lib/python3.5/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
  File "/Users/hanminsoo/.pyenv/versions/spec/lib/python3.5/site-packages/elasticsearch/client/indices.py", line 198, in delete
params=params)
  File "/Users/hanminsoo/.pyenv/versions/spec/lib/python3.5/site-packages/elasticsearch/transport.py", line 307, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
  File "/Users/hanminsoo/.pyenv/versions/spec/lib/python3.5/site-packages/elasticsearch/connection/http_urllib3.py", line 89, in perform_request
raise ConnectionError('N/A', str(e), e)
elasticsearch.exceptions.ConnectionError: ConnectionError(<urllib3.connection.HTTPConnection object at 0x110791e48>: Failed to establish a new connection: [Errno 61] Connection refused) caused by: NewConnectionError(<urllib3.connection.HTTPConnection object at 0x110791e48>: Failed to establish a new connection: [Errno 61] Connection refused)
All documents removed.
 Indexing 0 products

产品没有索引...

首先我认为是连接错误,

$ curl -v -X GET 127.0.0.1:9200

* Rebuilt URL to: 127.0.0.1:9200/
*   Trying 127.0.0.1...
* connect to 127.0.0.1 port 9200 failed: Connection refused
* Failed to connect to 127.0.0.1 port 9200: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 127.0.0.1 port 9200: Connection refused

但我设置settings.py

# Django Haystack
HAYSTACK_CONNECTIONS = {
    'default': {
    'ENGINE':'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
    'URL': 'http://127.0.0.1:9200/',
    'INDEX_NAME': 'haystack',
    'TIMEOUT': 10
    },
}

我尝试重新启动 elasticsearch,然后重新安装 pip,否则...

但是我不明白为什么.....

点冻结

appnope==0.1.0
certifi==2016.9.26
decorator==4.0.10
Django==1.9.7
django-debug-toolbar==1.5
django-extensions==1.7.2
django-haystack==2.5.1
djangorestframework==3.4.4
elasticsearch==1.9.0
get==0.0.0
httpie==0.9.6
ipython==5.0.0
ipython-genutils==0.1.0
pep8==1.7.0
pexpect==4.2.0
pickleshare==0.7.3
post==0.0.0
prompt-toolkit==1.0.3
ptyprocess==0.5.1
public==0.0.0
pyelasticsearch==1.4
Pygments==2.1.3
query-string==0.0.0
requests==2.12.2
setupfiles==0.0.0
simplegeneric==0.8.1
simplejson==3.10.0
six==1.10.0
sqlparse==0.2.1
traitlets==4.2.2
urllib3==1.19.1
wcwidth==0.1.7

Java-版本

java version "1.8.0_112"
Java(TM) SE Runtime Environment (build 1.8.0_112-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.112-b16, mixed mode)

这是因为你的ES服务器没有启动。

根据您的日志,您需要在 /usr/local/etc/elasticsearch/elasticsearch.yml 文件中将 discovery.zen.ping.timeout 更改为 discovery.zen.ping_timeout 并重新启动 ES。