gpt4 book ai didi

django - Django Haystack:Heroku Searchbox插件无法运行rebuild_index

转载 作者:行者123 更新时间:2023-12-02 23:38:46 25 4
gpt4 key购买 nike

我正在尝试使用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插件。我在那里也遇到类似的错误。

提前致谢。

最佳答案

掉了很多头发(:P)之后,我发现了问题所在!

这是问题所在:

port = es.port

es.port返回“无”。更改为
port = es.port or 80

现在可以了。

原来,当我从文档中复制代码时,我离开了“或80”部分。嘘!

关于django - Django Haystack:Heroku Searchbox插件无法运行rebuild_index,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26441557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com