Django haystack与elasticsearch,索引问题

时间:2013-04-20 07:12:04

标签: elasticsearch django-haystack

我使用django-haystack和elasticsearch但是索引存在问题。当重建我的索引

 python manage.py rebuild_index 
时,会出现以下错误:

Traceback (most recent call last):
  File "/home/palo/.virtualenvs/toro/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 210, in handle_label
    self.update_backend(label, using)
  File "/home/palo/.virtualenvs/toro/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 256, in update_backend
    do_update(backend, index, qs, start, end, total, self.verbosity)
  File "/home/palo/.virtualenvs/toro/local/lib/python2.7/site-packages/haystack/management/commands/update_index.py", line 78, in do_update
    backend.update(index, current_qs)
  File "/home/palo/.virtualenvs/toro/local/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 177, in update
    self.conn.bulk_index(self.index_name, 'modelresult', prepped_docs, id_field=ID)
  File "/home/palo/.virtualenvs/toro/src/pyelasticsearch/pyelasticsearch/client.py", line 95, in decorate
    return func(*args, query_params=query_params, **kwargs)
  File "/home/palo/.virtualenvs/toro/src/pyelasticsearch/pyelasticsearch/client.py", line 366, in bulk_index
    query_params=query_params)
  File "/home/palo/.virtualenvs/toro/src/pyelasticsearch/pyelasticsearch/client.py", line 221, in send_request
    **({'data': request_body} if body else {}))
  File "/home/palo/.virtualenvs/toro/src/requests/requests/sessions.py", line 387, in post
    return self.request('POST', url, data=data, **kwargs)
  File "/home/palo/.virtualenvs/toro/src/requests/requests/sessions.py", line 345, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/palo/.virtualenvs/toro/src/requests/requests/sessions.py", line 448, in send
    r = adapter.send(request, **kwargs)
  File "/home/palo/.virtualenvs/toro/src/requests/requests/adapters.py", line 324, in send
    raise Timeout(e)
Timeout: HTTPConnectionPool(host='127.0.0.1', port=9200): Request timed out. (timeout=10)
Timeout: HTTPConnectionPool(host='127.0.0.1', port=9200): Request timed out. (timeout=10)

我用django-haystack - 2.0.0-beta,pyelasticsearch - 0.5,elasticsearch 0.20.6,java version“1.6.0_24”


干草堆设置


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

我确定我的弹性搜索服务正在运行。

3 个答案:

答案 0 :(得分:14)

这并不一定意味着您的es服务器已关闭,尤其是当您使用curl -I "127.0.0.1:9200"返回合理的内容时。更可能的是,考虑到所涉及的连接速度,这是您的请求的问题,根本没有足够的时间。

有趣的是,pyelasticsearch中设置的默认超时为60秒,请参阅https://github.com/rhec/pyelasticsearch/blob/master/pyelasticsearch/client.py中的def __init__(self, urls, timeout=60, max_retries=0, revival_delay=300):。但是,haystack根据https://github.com/toastdriven/django-haystack/blob/master/haystack/backends/__init__.pyself.timeout = connection_options.get('TIMEOUT', 10)的默认设置(10秒)覆盖它。

如您所见,haystack允许您通过在引擎配置中添加'TIMEOUT': 60,来轻松修改设置。

并解决了:))

答案 1 :(得分:1)

我也有类似的问题

sudo service elasticsearch restart

然后它起作用了

答案 2 :(得分:-2)

你在跑吗

bin/elasticsearch -f 

我认为你没有运行searchengine。