我正在尝试使用Heroku上的elasticsearch实现我的Django应用程序的Haystack搜索。
我按照此处的说明操作:https://devcenter.heroku.com/articles/searchbox#using-haystack-with-django设置Searchbox插件。
settings.py:
from urlparse import urlparse
es = urlparse(os.environ.get('SEARCHBOX_URL'))
port = es.port
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': es.scheme + '://' + es.hostname + ':' + str(port),
'INDEX_NAME': 'haystack',
},
}
if es.username:
HAYSTACK_CONNECTIONS['default']['KWARGS'] = {"http_auth": es.username + ':' + es.password}
但是,当我尝试运行时
heroku run python manage.py rebuild_index
我收到以下错误跟踪:
Removing all documents from your index because you said so.
No handlers could be found for logger "elasticsearch"
Failed to clear Elasticsearch index: ConnectionError(('Connection aborted.', gai
error(-2, 'Name or service not known'))) caused by: ProtocolError(('Connection a
borted.', gaierror(-2, 'Name or service not known')))
All documents removed.
Indexing 133 links
ERROR:root:Error updating links using default
Traceback (most recent call last):
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/management/comm
ands/update_index.py", line 189, in handle_label
self.update_backend(label, using)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/management/comm
ands/update_index.py", line 234, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/management/comm
ands/update_index.py", line 89, in do_update
backend.update(index, current_qs)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/backends/elasti
csearch_backend.py", line 187, in update
bulk_index(self.conn, prepped_docs, index=self.index_name, doc_type='modelre
sult')
File "/app/.heroku/python/lib/python2.7/site-packages/elasticsearch/helpers/__
init__.py", line 145, in bulk
for ok, item in streaming_bulk(client, actions, **kwargs):
File "/app/.heroku/python/lib/python2.7/site-packages/elasticsearch/helpers/__
init__.py", line 104, in streaming_bulk
resp = client.bulk(bulk_actions, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/elasticsearch/client/uti
ls.py", line 68, in _wrapped
return func(*args, params=params, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/elasticsearch/client/__i
nit__.py", line 646, in bulk
params=params, body=self._bulk_body(body))
File "/app/.heroku/python/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 "/app/.heroku/python/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.', gaierror(-2, 'Name or s
ervice not known'))) caused by: ProtocolError(('Connection aborted.', gaierror(-
2, 'Name or service not known')))
Traceback (most recent call last):
File "maldio_project/manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
_init__.py", line 399, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
_init__.py", line 392, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/b
ase.py", line 242, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/b
ase.py", line 285, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/management/comm
ands/rebuild_index.py", line 16, in handle
call_command('update_index', **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/_
_init__.py", line 159, in call_command
return klass.execute(*args, **defaults)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/b
ase.py", line 285, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/management/comm
ands/update_index.py", line 184, in handle
return super(Command, self).handle(*items, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/management/b
ase.py", line 385, in handle
label_output = self.handle_label(label, **options)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/management/comm
ands/update_index.py", line 189, in handle_label
self.update_backend(label, using)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/management/comm
ands/update_index.py", line 234, in update_backend
do_update(backend, index, qs, start, end, total, self.verbosity)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/management/comm
ands/update_index.py", line 89, in do_update
backend.update(index, current_qs)
File "/app/.heroku/python/lib/python2.7/site-packages/haystack/backends/elasti
csearch_backend.py", line 187, in update
bulk_index(self.conn, prepped_docs, index=self.index_name, doc_type='modelre
sult')
File "/app/.heroku/python/lib/python2.7/site-packages/elasticsearch/helpers/__
init__.py", line 145, in bulk
for ok, item in streaming_bulk(client, actions, **kwargs):
File "/app/.heroku/python/lib/python2.7/site-packages/elasticsearch/helpers/__
init__.py", line 104, in streaming_bulk
resp = client.bulk(bulk_actions, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/elasticsearch/client/uti
ls.py", line 68, in _wrapped
return func(*args, params=params, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/elasticsearch/client/__i
nit__.py", line 646, in bulk
params=params, body=self._bulk_body(body))
File "/app/.heroku/python/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 "/app/.heroku/python/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.'
, gaierror(-2, 'Name or service not known'))) caused by: ProtocolError(('Connect
ion aborted.', gaierror(-2, 'Name or service not known')))
我做错了什么?如何在Heroku上索引我的数据?
编辑:我也尝试在Heroku中使用Bonsai插件。我也遇到了类似的错误。
提前致谢。
答案 0 :(得分:1)
失去了很多头发(:P)之后,我发现了问题所在!
这就是问题所在:
port = es.port
es.port正在回归&#34;无&#34;。将其更改为
port = es.port or 80
现在它有效。
原来我离开了&#34;或80&#34;部分当我从文档中复制代码。啧!