我正在尝试将django-haystack与djangorestframework和elasticsearch一起使用,并遵循教程here
我在虚拟环境中安装了以下软件包
djangorestframework==3.5.4
drf-haystack==1.6.1
elasticsearch==1.5.0
HAYSTACK_CONNECTIONS = {
'default': {
'ENGINE': 'haystack.backends.elasticsearch_backend.ElasticsearchSearchEngine',
'URL': 'http://127.0.0.1:9200/',
'INDEX_NAME': 'haystack',
},
}
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
}
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'drf',
'haystack',
'rest_framework',
'rest_framework.authtoken',
]
但每当我尝试将rebuild_index设为python manage.py rebuild_inex
时,或者每当我尝试使用http://localhost:8000/api/v1/location/search/?city=Hyderabad
处的API检索结果时,我都会收到以下错误,而且我已经搜索了很多关于此问题的信息但是我无法能够得到任何帮助
Failed to query Elasticsearch using 'city:(Hyderabad)': TransportError(400, u'parsing_exception')
Traceback (most recent call last):
File "/Users/shivakrishna/.virtualenvs/ipitch/lib/python2.7/site-packages/haystack/backends/elasticsearch_backend.py", line 524, in search
_source=True)
File "/Users/shivakrishna/.virtualenvs/ipitch/lib/python2.7/site-packages/elasticsearch/client/utils.py", line 69, in _wrapped
return func(*args, params=params, **kwargs)
File "/Users/shivakrishna/.virtualenvs/ipitch/lib/python2.7/site-packages/elasticsearch/client/__init__.py", line 504, in search
params=params, body=body)
File "/Users/shivakrishna/.virtualenvs/ipitch/lib/python2.7/site-packages/elasticsearch/transport.py", line 307, in perform_request
status, headers, data = connection.perform_request(method, url, params, body, ignore=ignore, timeout=timeout)
File "/Users/shivakrishna/.virtualenvs/ipitch/lib/python2.7/site-packages/elasticsearch/connection/http_urllib3.py", line 89, in perform_request
self._raise_error(response.status, raw_data)
File "/Users/shivakrishna/.virtualenvs/ipitch/lib/python2.7/site-packages/elasticsearch/connection/base.py", line 105, in _raise_error
raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
RequestError: TransportError(400, u'parsing_exception')
我已经读过一些上述错误的地方因为弹性搜索版本超过2.0.0,但我已经安装了1.5.0但仍然面临上述错误。
任何人都可以让我知道如何解决这个问题吗?
答案 0 :(得分:0)
当谈到Django-Python时,Elasticsearch有一些依赖关系。请安装pyelasticsearch,其中将安装所有依赖项,如urllib3,elasticsearch等。
确保在安装后弹性搜索版本是1.xy(2.xy也可以这样做),否则将elasticsearch降级为< 2.0.0,您可以从requirements.txt
或其他方式执行此操作。
此外,请检查并在http://127.0.0.1:9200/
上发布查询结果,因为这会显示您系统上的弹性搜索版本。我认为这应该是问题,因为您附加的日志显示了与版本问题相关的错误,我也面临了几天。
更重要的是,你启动了elasticsearch服务器吗?检查docs也是如此。
让我知道这是否有效。