问题描述
我使用的是django 1.4,django-haystack 2.0和Elasticsearch 0.19.1我有一个这样的SearchIndex:
从haystack导入索引
/ pre>
从core.models import Project
类ProjectIndex(indexes.RealTimeSearchIndex,indexes.Indexable):
text = indexes.CharField(document = True,use_template =真的)
location = indexes.LocationField(model_attr ='get_location')
def get_model(self):
return Project
和类似的项目模型:
class Project BaseModel):
name = models.CharField(_(u'ProjeAdı'),max_length = 50)
latitude = models.FloatField()
longitude = models.FloatField()
def get_location(self):
#记住,经度FIRST!
返回点(self.longitude,self.latitude)
所以我想查询项目对象按距离特定坐标从近到远:
....
location = Point(project.longitude, project.latitude)
projects = SearchQuerySet()。models(Project).distance('location',location).order_by('distance')
但是我收到此错误:
无法使用'查询Elasticsearch: ':返回的非OK状态代码(500)包含u'SearchPhaseExecutionException [无法执行phase [query],total failure; shardFailures {[jmUkmHkDTX-bo9DhFJdtSw] [skp] [2]:QueryPhaseExecutionException [[skp] [2]:query [filtered(ConstantScore(NotDeleted(cache(QueryWrapperFilter(django_ct:core.project)))) - > cache :modelResult)],从[0],size [10],sort []:查询失败[执行主查询失败]];嵌套:ElasticSearchIllegalArgumentException [field [location]不是geo_point字段]; } {[jmUkmHkDTX-bo9DhFJdtSw] [skp] [4]:QueryPhaseExecutionException [[skp] [4]:query [filtered(ConstantCount(NotDeleted(cache(QueryWrapperFilter(django_ct:core.project)))) - > cache :modelResult)],从[0],size [10],sort []:查询失败[执行主查询失败]];嵌套:ElasticSearchIllegalArgumentException [field [location]不是geo_point字段];
有什么问题?
解决方案可能是您的位置字段的类型方面被映射错误。这可能是由您用于映射的api引起的。映射中的某些方面可以更改,但不能改变字段的类型方面。因此,您必须使用geo_point类型的位置字段创建新的映射,并重新索引您的文档。
I'm using django 1.4, django-haystack 2.0 and Elasticsearch 0.19.1 I have an SearchIndex like that:
from haystack import indexes from core.models import Project class ProjectIndex(indexes.RealTimeSearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_template=True) location = indexes.LocationField(model_attr='get_location') def get_model(self): return Project
and Project model like that:
class Project(BaseModel): name = models.CharField(_(u'Proje Adı'), max_length=50) latitude = models.FloatField() longitude = models.FloatField() def get_location(self): # Remember, longitude FIRST! return Point(self.longitude, self.latitude)
So I want to query Project objects by distance specific coordinate from near to far:
.... location = Point(project.longitude, project.latitude) projects = SearchQuerySet().models(Project).distance('location', location).order_by('distance')
But I'm getting this error:
Failed to query Elasticsearch using ':': Non-OK status code returned (500) containing u'SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[jmUkmHkDTX-bo9DhFJdtSw][skp][2]: QueryPhaseExecutionException[[skp][2]: query[filtered(ConstantScore(NotDeleted(cache(QueryWrapperFilter(django_ct:core.project)))))->cache(_type:modelresult)],from[0],size[10],sort[]: Query Failed [Failed to execute main query]]; nested: ElasticSearchIllegalArgumentException[field [location] is not a geo_point field]; }{[jmUkmHkDTX-bo9DhFJdtSw][skp][4]: QueryPhaseExecutionException[[skp][4]: query[filtered(ConstantScore(NotDeleted(cache(QueryWrapperFilter(django_ct:core.project)))))->cache(_type:modelresult)],from[0],size[10],sort[]: Query Failed [Failed to execute main query]]; nested: ElasticSearchIllegalArgumentException[field [location] is not a geo_point field]; }]'.
What is wrong?
解决方案Probably the "type" aspect of your location field is mapped wrong. This could be caused by the api that you used for mapping. Some aspects in a mapping can be changed, but not the "type" aspect of a field. So you'll have to create a new mapping with location field in geo_point type, and reindex your docs.
这篇关于Django Haystack按距离顺序由Elasticsearch后端排序,而不是geo_point字段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!