我正在使用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 }}
一切似乎都正确我想,我会关注documentation和tutorial。
但现在,当我触发时:
$ python manage.py rebuild_index
我收到此错误:
pyelasticsearch.exceptions.InvalidJsonResponseError: <Response [404]>
如果有人知道为什么? :)
谢谢。
答案 0 :(得分:1)
您正在运行Django Server的同一端口上运行Elastic Search Server。
将端口从8000
更改为其他内容,然后它才能正常工作!