Hug*_*own 4 django django-haystack elasticsearch
我试图在我的本地开发环境(运行Ubuntu 12.04的vagrant VM)上设置ElasticSearch/Haystack,我无法解决重新索引过程.
ES正在运行,我已经创建了一个新索引(我使用elasticsearch-head来查看浏览器中的索引状态).我可以创建一个新索引并查询它,所以我知道ES正在工作.
我的问题是Haystack rebuild_index命令:
(.venv)vagrant@precise32:/app$ foreman run ./manage.py rebuild_index
WARNING: This will irreparably remove EVERYTHING from your search index in connection 'default'.
Your choices after this are to restore from backups or rebuild via the `rebuild_index` command.
Are you sure you wish to continue? [y/N] y
Removing all documents from your index because you said so.
DEBUG Making a request equivalent to this: curl -XDELETE 'http://127.0.0.1:9200/test_app' -d '""'
INFO Starting new HTTP connection (1): 127.0.0.1
DEBUG "DELETE /test_app HTTP/1.1" 200 31
DEBUG response status: 200
DEBUG got response {u'acknowledged': True, u'ok': True}
DEBUG Making a request equivalent to this: curl -XPOST 'http://127.0.0.1:9200/test_app/_refresh' -d '""'
DEBUG "POST /test_app/_refresh HTTP/1.1" 404 66
DEBUG response status: 404
Failed to clear Elasticsearch index: (404, u'IndexMissingException[[test_app] missing]')
ERROR Failed to clear Elasticsearch index: (404, u'IndexMissingException[[test_app] missing]')
All documents removed.
Run Code Online (Sandbox Code Playgroud)
看看这个loggging - 似乎Haystack正在尝试刷新它刚刚删除的索引 - 这总是会失败.
我究竟做错了什么?
[更新1]
如果我拆分POST请求,我可以运行它:
(.venv)vagrant@precise32:/app$ curl -XPOST 'http://127.0.0.1:9200/test_app/'
{"ok":true,"acknowledged":true}
(.venv)vagrant@precise32:/app$ curl -XPOST 'http://127.0.0.1:9200/test_app/_refresh' -d '""'
{"ok":true,"_shards":{"total":10,"successful":5,"failed":0}}
Run Code Online (Sandbox Code Playgroud)
[更新2]
深入研究代码,运行时调用的ES后端方法clear_index是:
def clear(self, models=[], commit=True):
[...]
if not models:
self.conn.delete_index(self.index_name)
else:
[...]
if commit:
self.conn.refresh(index=self.index_name)
Run Code Online (Sandbox Code Playgroud)
哪个看起来不对,因为它会调用conn.refresh它刚刚删除的索引?
[更新3]
我认为上面的错误可能是一个红色的鲱鱼,因为管理命令会忽略错误并继续,给出这个错误,我认为这个错误更严重:
(.venv)vagrant@precise32:/app$ foreman run ./manage.py update_index --verbosity=3
Skipping '<class 'django.contrib.auth.models.Permission'>' - no index.
Skipping '<class 'django.contrib.auth.models.Group'>' - no index.
Skipping '<class 'django.contrib.auth.models.User'>' - no index.
Skipping '<class 'django.contrib.contenttypes.models.ContentType'>' - no index.
Skipping '<class 'django.contrib.sessions.models.Session'>' - no index.
Skipping '<class 'django.contrib.sites.models.Site'>' - no index.
Skipping '<class 'django.contrib.admin.models.LogEntry'>' - no index.
Skipping '<class 'django.contrib.flatpages.models.FlatPage'>' - no index.
ERROR Error updating test_app using default
Traceback (most recent call last):
File "/home/vagrant/.venv/src/django-haystack/haystack/management/commands/update_index.py", line 210, in handle_label
self.update_backend(label, using)
File "/home/vagrant/.venv/src/django-haystack/haystack/management/commands/update_index.py", line 239, in update_backend
end_date=self.end_date)
File "/home/vagrant/.venv/src/django-haystack/haystack/indexes.py", line 157, in build_queryset
index_qs = self.index_queryset(using=using)
TypeError: index_queryset() got an unexpected keyword argument 'using'
Traceback (most recent call last):
File "./manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/home/vagrant/.venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/home/vagrant/.venv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/vagrant/.venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/home/vagrant/.venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/home/vagrant/.venv/src/django-haystack/haystack/management/commands/update_index.py", line 184, in handle
return super(Command, self).handle(*items, **options)
File "/home/vagrant/.venv/local/lib/python2.7/site-packages/django/core/management/base.py", line 341, in handle
label_output = self.handle_label(label, **options)
File "/home/vagrant/.venv/src/django-haystack/haystack/management/commands/update_index.py", line 210, in handle_label
self.update_backend(label, using)
File "/home/vagrant/.venv/src/django-haystack/haystack/management/commands/update_index.py", line 239, in update_backend
end_date=self.end_date)
File "/home/vagrant/.venv/src/django-haystack/haystack/indexes.py", line 157, in build_queryset
index_qs = self.index_queryset(using=using)
TypeError: index_queryset() got an unexpected keyword argument 'using'
Run Code Online (Sandbox Code Playgroud)
[更新4]
好的 - 所以这是我的错,我使用的是旧search_indexes.py文件,而且我的index_queryset()方法不正确.我不会关闭它,因为它可能对其他人有用.
自己回答这个问题 - 尽管这只是承认我自己的愚蠢.
我search_indexes.py从干草堆的1.x版本中携带了一个文件到我们项目的一个新分支中,该分支使用的是Haystack的2.x版本,其配置略有不同.在新版本中,该index_queryset()方法现在需要一个新using参数(默认为None).旧版本不需要这个.
因此,新签名应为:
def index_queryset(self, using=None):
pass
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3597 次 |
| 最近记录: |