版本:
CentOS - 6.4 (Final)
Haystack - 2.1.0
ElasticSearch - 1.2.1
Java - 1.7.0_55
Django-cms - 2.3.1
pyelasticsearch - 0.6
我在CentOS机器的Django项目中使用ElasticSearch时遇到问题。我曾经在Ubuntu机器上配置Elasticsearch / Haystack,从来没有这样的问题。
我收到此错误Parse Failure [No parser for element [y]]
,但我有一个空索引。我试图确切地知道错误的来源,所以我尝试了:
起初我认为错误是由索引的内容,我试图索引的数据引起的,但在删除/清除索引之后我仍然遇到了同样的错误。
我试图在模板中显示一个空的查询集(因为我不知道还有什么试图找出问题所在)
其他信息
当我用python manage.py shell
打开Django shell并生成
from haystack.query import SearchQuerySet
SearchQuerySet()
SearchQuerySet().all()
SearchQuerySet().filter(content='any_text')
这种查询运行没有问题,如果找不到任何内容则返回空的查询集,或者如果发现某些内容则返回查询集。尝试在视图中使用该命令并将结果返回到模板时,我收到错误和问题。在shell中一切正常,如果索引为空则返回空查询集,如果索引有值则返回它必须返回的值
search_indexes.py
import datetime
from haystack import indexes
from django.contrib.auth.models import User
from cms.models import CMSPlugin, Page
class CMSPluginIndex(indexes.SearchIndex, indexes.Indexable):
text = indexes.CharField(document=True, use_template=True)
plugin_type = indexes.CharField(model_attr='plugin_type')
language = indexes.CharField(model_attr='language')
def get_model(self):
return CMSPlugin
def index_queryset(self, using=None):
"""Used when the entire index for model is updated."""
return self.get_model().objects.all()
cms_plugin_text.txt
{{object.language}} # I added just this field to make sure is not the content of this
views.py的恢复
def search_query(request):
sqs = SearchQuerySet().all()
return HttpResponse(sqs)
Django错误
Invalid JSON returned from ES: <Response [404]>
Exception Value: Invalid JSON returned from ES: <Response [404]>
控制台中的完整ElasticSearch错误跟踪
[DEBUG][action.search.type] [Futurist] [haystack][2], node[inisR695RtGZ_WnEnkRr1w], [P], s[STARTED]: Failed to execute [org.elasticsearch.action.search.SearchRequest@28cfe3d9] lastShard [true]
org.elasticsearch.search.SearchParseException: [haystack][2]: from[-1],size[-1]: Parse Failure [Failed to parse source [{"\ud900\udc71\ud840\udc65y\u0000\ud840\udc61":
{"\uda00\udc66\ud8c0\udc6c\ud840\udc65\ud8c0\udc65\ud8c0\udc00a\uda00\udc42\udac0\udc65":
{"\uda00\udc66\ud8c0\udc6c\ud840\udc65\u0000\ud880\udc25\udbc0\udc20":
{"\ud800\udc66\ud900\udc75\uda00\udc72\u0000\ud880\udc25\ud8c0\udc20":
{"\ud900\udc71\ud840\udc65y\u0000\ud840\udc61":
{"\ud900\udc71\ud840\udc65\udb80\udc79\ud8c0\udc73\uda00\udc72\ud980\udc6e\u0000\u0000\uda00
\udc64\ud8c0\udc73\udb40\udc61\ud900\udc63": {"\ud900\udc71\ud840\udc65y\u0000\ud840\udc61":
"\uda40\udc64\udb40\udc61\udb80\udc67\ud880\udc5f\uda40\udc74\ud880\udc28\ud880\udc6d\ud880\
udc2e\ud880\udc6d\udac0\udc70\ud980\udc75\udb40\udc69\udb80\udc20\udbc0\udc52\ud840\udc70\ud
b40\udc6f\uda80\udc6f\udac0\udc61\ud880\udc5f\ud800\udc68\ud900\udc72\udb40\udc64\udb80\udc6
3\udb40\udc75\ud840\udc74\uda00\udc79\ud880\udc00\u0000\u0002\u0000\uda34\ude80\u7f8eD\u0000
\udbbf\udfff\udbbf\udfff\u0000\ud917\udc22\udbcc\udc38\ud899\udc75\ud917\udc36\udbcc\udc39\u
d899\udc75\ud917\udc35\udbcc\udc61\ud899\udc75\ud917\udc32\udbcc\udc30\ud9d9\udc75\ud917\udc
30\ud90c\ude63\ud9d9\udc75"}},
"\ud880\udc5f\ud880\udc61\ud900\udc68\u0000\udb80\udc70\udb40\udc69": true}},
"\ud900\udc71\ud840\udc65y\u0000\ud840\udc61":
{"\ud900\udc71\ud840\udc65\udb80\udc79\ud8c0\udc73\uda00\udc72\ud980\udc6e\u0000\u0000\uda00
\udc64\ud8c0\udc73\udb40\udc61\ud900\udc63": {"\ud900\udc71\ud840\udc65y\u0000\ud840\udc61":
"\ud900\udc28)\ud89d\udc30",
"\ud900\udc64\ud800\udc66\udac0\udc75\udb80\udc74\udbc0\udc6f\ud840\udc65\ud8c0\udc61\ud840\
udc6f\u0000\ud99b\udf6c\udb40\udc61\udac0\udc61\uda40\udc79\udb80\udc65\uda00\udc77\ud8c0\ud
c6c": "\udb40\udc41D\ud8c0\udc67",
"\ud900\udc64\ud800\udc66\udac0\udc75\udb80\udc74\uda00\udc66\udac0\udc65d\u0000\u0001\u0000
\uda18\ude40\u7f8e\u0001": "\ud900\udc74\ud8c0\udc78\udbc0\udc00\udb00\udc65",
"\ud900\udc61\udb80\udc74\ud980\udc5f\udb40\udc65\ud840\udc65\ud8c0\udc61\udb80\udc65\ud9c0\
udc70\ud800\udc72\ud900\udc73\ud800\udc5f\ud900\udc75\uda00\udc72\ud880\udc65\ud8c0\udc00\u7
36c\u0000\u0000\udba4\udc30\u7f8e\udbbf\udffe\udbbf\udfff\u0001\u0000\u0001\u0000\uda38\ude8
0\u7f8e": true,
"\udb40\udc61\udac0\udc61\uda40\udc79\udb80\udc65\uda00\udc77\ud8c0\udc6c\ud800\udc63\ud8c0\
udc72\ud880\udc00\u7f8e\b\u0000\uda34\ude80\u7f8e\u0003\u0000": true}}}},
"\ud840\udc66\udb00\udc6f\ud840\udc00\u7f8e": 0, "\uda00\udc73\ud900\udc7a\u0000\u0000":
20}]]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:634)
at org.elasticsearch.search.SearchService.createContext(SearchService.java:507)
at org.elasticsearch.search.SearchService.createAndPutContext(SearchService.java:480)
at org.elasticsearch.search.SearchService.executeQueryPhase(SearchService.java:252)
at org.elasticsearch.search.action.SearchServiceTransportAction.sendExecuteQuery(SearchServiceTransportAction.java:202)
at org.elasticsearch.action.search.type.TransportSearchQueryThenFetchAction$AsyncAction.sendExecuteFirstPhase(TransportSearchQueryThenFetchAction.java:80)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:216)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction.performFirstPhase(TransportSearchTypeAction.java:203)
at org.elasticsearch.action.search.type.TransportSearchTypeAction$BaseAsyncAction$2.run(TransportSearchTypeAction.java:186)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
at java.lang.Thread.run(Thread.java:744)
Caused by: org.elasticsearch.search.SearchParseException: [haystack][3]: from[-1],size[-1]: Parse Failure [No parser for element [y]]
at org.elasticsearch.search.SearchService.parseSource(SearchService.java:620)
... 11 more
如果您需要任何其他信息来弄清楚这里发生的事情,请不要犹豫,我会尽快发布。
我想问题可能来自pyelasticsearch
。任何人都有类似的问题吗?
修改
我尝试了另一件事,我在Ubuntu服务器上安装了ElasticSearch,并将查询从CentOS发送到Ubuntu。我从django-cms索引CMSPlugin
模型,似乎插件的正文/文本包含一些特殊字符,Java或Elasticsearch尝试解析失败。这是第一个使ElasticSearch / Java崩溃的字符串\ud900\udc71\ud840\udc65y\u0000\ud900\udc74
。
我在python控制台中试过这个
c=u'\ud900\udc71\ud840\udc65y\u0000\ud900\udc74'
print c
输出:y
编辑2
我想知道CentOS上的Java是否有问题,我尝试将Java版本降级到1.6并且没有工作
编辑3
现在我直接使用ElasticSearch,使用urllib2查询弹性搜索,避免使用Haystack。 ElasticSearch完美地回答了问题(我必须管理JSON)。我想问题是Haystack如何生成或解析查询,因为当我尝试使用SearchQuerySet()
并使用shell或在视图中创建SearchQuerySet().filter(content='whatever')
之类的东西时,ElasticSearch会因上面的错误而崩溃,但是有效做CURL
编辑4
最后,我在不使用Haystack的情况下直接使用最后一个ElasticSearch。似乎问题是Haystack / pyelasticsearch如何格式化要发送给ES的查询,它无法解析编码并在每个请求中失败。
我没有找到任何解决方案,只是避免与Haystack合作,如果有人能指出解决方案会很棒,我也会发送电子邮件给Haystack的人,看他们是否已经注意到了这个问题。
编辑5
如果有人在CentOS上配置了Haystack,我将不胜感激任何有关配置和软件版本的指南。我在CentOS上运行ElasticSearch,但是我直接通过ElasticSearch管理查询,完全忽略了Haystack
答案 0 :(得分:1)
我认为这里的问题可能与使用pyelasticsearch有关。对于较新的django-haystack(我相信> 1.0),您需要使用elasticsearch-py。如果你尝试pip install elasticsearch
,它应该安装最新的库(1.1.1)并修复你的问题。作为额外的&#34;以防万一&#34;测量,您可以尝试使用pip uninstall pyelasticsearch
删除pyelasticsearch。这种依赖关系以非常明显的方式显示,例如:http://django-haystack.readthedocs.org/en/latest/installing_search_engines.html#elasticsearch