Amit
Amit

Reputation: 1680

Django Haystack: Heroku Searchbox addon fails to run rebuild_index

I am trying to implement Haystack search for my Django application using elasticsearch on Heroku.

I followed the instructions here: https://devcenter.heroku.com/articles/searchbox#using-haystack-with-django to set up the Searchbox addon.

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}

However, when I try to run

heroku run python manage.py rebuild_index

I am getting the following error trace:

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')))

What am I doing wrong? How do I index my data on Heroku?

Edit: I also tried using the Bonsai addon in Heroku. I am getting a similar error there too.

Thanks in advance.

Upvotes: 1

Views: 772

Answers (1)

Amit
Amit

Reputation: 1680

After losing a lot of hair (:P), I figured out what the problem was!

This was the issue:

port = es.port

es.port was returning "None". Changed it to

port = es.port or 80

and now it works.

Turns out I left the "or 80" part when I copied the code from the documentation. Sheesh!

Upvotes: 1

Related Questions