1

我正在使用 Django 和 Haystack 模块来创建搜索引擎。我想使用 ElasticSearch。我已经安装并启动它:

$ brew install elasticsearch
$ elasticsearch -f -D es.config=/usr/local/Cellar/elasticsearch/0.90.2/config/elasticsearch.yml

我的设置似乎正确且有效:

# Haystack configuration
HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
        'URL': 'http://127.0.0.1:8000/',
        'INDEX_NAME': 'haystack',
    },
}
HAYSTACK_SIGNAL_PROCESSOR = 'haystack.signals.RealtimeSignalProcessor'

这是我的搜索索引:

from haystack import indexes
from account.models import Profile

class ProfileIndex(indexes.SearchIndex, indexes.Indexable):
    text = indexes.CharField(document=True, use_template=True)
    first_name = indexes.CharField(model_attr='first_name')
    last_name = indexes.CharField(model_attr='last_name')

    def get_model(self):
        return Profile

和我的 profile_text.txt:

{{ object.first_name }}
{{ object.last_name }}

我猜一切似乎都是正确的,我遵循文档和本教程

但是现在,当我触发时:

$ python manage.py rebuild_index

我收到此错误:

pyelasticsearch.exceptions.InvalidJsonResponseError: <Response [404]>

如果有人知道为什么?:)

谢谢你。

4

1 回答 1

1

您正在运行 Django 服务器的同一端口上运行 Elastic Search 服务器。

将端口从更改为8000其他端口,然后它将起作用!

于 2013-09-18T13:24:40.657 回答