不能让弹性搜索与Django一起工作 [英] Can't get Elasticsearch working with Django

查看:188
本文介绍了不能让弹性搜索与Django一起工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Django和Haystack与Elasticsearch作为Ubuntu 14.04的后端。我有Elasticsearch和Haystack安装。



当我运行python manage.py runserver时收到的错误:

 我@ ubuntu:$ python manage.py runserver 
验证模型...

0找到错误
2015年1月31日 - 17: 40:37
Django版本1.5.4,使用设置'website_project.settings'
开发服务器正在运行http://127.0.0.1:8000/
使用CONTROL-C退出服务器。
追溯(最近的最后一次调用):
文件/home/me/.pythonbrew/pythons/Python-2.7.5/lib/python2.7/wsgiref/handlers.py,第85行,在运行
self.result = application(self.environ,self.start_response)
文件/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py ,第72行,__call__
return self.application(environ,start_response)
文件/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py ,第243行,__call__
signals.request_started.send(sender = self .__ class__)
文件/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher。 py,第170行,发送
response = receiver(signal = self,sender = sender,** named)
文件/usr/local/lib/python2.7/dist-packages/haystack /__init__.py,第60行,在reset_search_queries
中的conn.all()中的conn:
文件/usr/local/lib/python2.7/dist-packages/haystack/utils/loading .py,第111行,全部为
return [self [alias] for别名在self.connections_info]
文件/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py,第99行,__getitem__
self._connections [key ] = load_backend(self.connections_info [key] ['ENGINE'])(using = key)
文件/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py ,line 52,in load_backend
return import_class(full_backend_path)
文件/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py,第19行,在import_class
module_itself = importlib.import_module(module_path)
文件/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py,第35行,import_module
__import __(name)
文件/usr/local/lib/python2.7/dist-packages/haystack/backends/elasticsearch_backend.py,第26行在< module>
raise MissingDependency(''''''''''''''''''''''''需要安装'elasticsearch',请参考文档)
MissingDependency:'elasticsearch'后端需要安装'elasticsearch'。请参阅文档。

我的PYTHONPATH是

 家/我/ .pythonbrew /蟒蛇/ Python的2.7.5 / lib目录下:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages 

我在我的INSTALLED_APPS列表中有'haystack',并具有以下配置:

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

我可以用



开始弹性搜索$ pre> sudo service elasticsearch start

当我去 http:// localhost:9200 /
我看到

  {
status:200,
name:Stranger,
version:{
number:1.1。 1,
build_hash:somehash,
build_timestamp:2014-04-16T14:27:12Z,
build_snapshot:false,
lucene_version:4.7
},
tagline:你知道,为搜索
}

似乎我已经安​​装了Elasticsearch,所以我不知道为什么我得到了

  MissingDependency:'elasticsearch'后端需要安装'elasticsearch'。请参阅文档。 

错误

解决方案

似乎您已经修复了它,但对于未来的Google员工:一些人在2014-2015年期间,干草堆版本有麻烦。修复2.1.0版本似乎修复了,直接从git下载2.4.0:

  pip install git + https://github.com/django-haystack/django-haystack 

更新:pypi的当前版本的haystack的作品(nov 2015),一定要更新!


I'm trying to use Django and Haystack with Elasticsearch as the backend on Ubuntu 14.04. I have Elasticsearch and Haystack installed.

The error I receive when I run python manage.py runserver:

me@ubuntu:$ python manage.py runserver
Validating models...

0 errors found
January 31, 2015 - 17:40:37
Django version 1.5.4, using settings 'website_project.settings'
Development server is running at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Traceback (most recent call last):
  File "/home/me/.pythonbrew/pythons/Python-2.7.5/lib/python2.7/wsgiref/handlers.py", line 85, in run
    self.result = application(self.environ, self.start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/contrib/staticfiles/handlers.py", line 72, in __call__
    return self.application(environ, start_response)
  File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/wsgi.py", line 243, in __call__
    signals.request_started.send(sender=self.__class__)
  File "/usr/local/lib/python2.7/dist-packages/django/dispatch/dispatcher.py", line 170, in send
    response = receiver(signal=self, sender=sender, **named)
  File "/usr/local/lib/python2.7/dist-packages/haystack/__init__.py", line 60, in reset_search_queries
    for conn in connections.all():
  File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 111, in all
    return [self[alias] for alias in self.connections_info]
  File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 99, in __getitem__
    self._connections[key] = load_backend(self.connections_info[key]['ENGINE'])(using=key)
  File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 52, in load_backend
    return import_class(full_backend_path)
  File "/usr/local/lib/python2.7/dist-packages/haystack/utils/loading.py", line 19, in import_class
    module_itself = importlib.import_module(module_path)
  File "/usr/local/lib/python2.7/dist-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "/usr/local/lib/python2.7/dist-packages/haystack/backends/elasticsearch_backend.py", line 26, in <module>
    raise MissingDependency("The 'elasticsearch' backend requires the installation of 'elasticsearch'. Please refer to the documentation.")
MissingDependency: The 'elasticsearch' backend requires the installation of 'elasticsearch'. Please refer to the documentation.

My PYTHONPATH is

home/me/.pythonbrew/pythons/Python-2.7.5/lib:/usr/local/lib/python2.7/dist-packages:/usr/lib/python2.7/dist-packages

I have 'haystack' in my list of INSTALLED_APPS and have the following config:

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

I can start Elasticsearch with

sudo service elasticsearch start

and when I go to http://localhost:9200/ I see

 {
  "status" : 200,
  "name" : "Stranger",
  "version" : {
    "number" : "1.1.1",
    "build_hash" : "somehash",
    "build_timestamp" : "2014-04-16T14:27:12Z",
    "build_snapshot" : false,
    "lucene_version" : "4.7"
  },
  "tagline" : "You Know, for Search"
}

It seems like I have Elasticsearch installed so I don't know why I am getting the

 MissingDependency: The 'elasticsearch' backend requires the installation of 'elasticsearch'. Please refer to the documentation.

error.

解决方案

Seems you've already fixed it, but for future Googlers: some people have trouble with the Haystack versions on pip around 2014-2015. Fixing the version at 2.1.0 seems to fix it, as does downloading 2.4.0 directly from git:

pip install git+https://github.com/django-haystack/django-haystack

UPDATE: The current version of haystack in pypi works (nov 2015), be sure to update!

这篇关于不能让弹性搜索与Django一起工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆