elasticsearch Django Haystack通过Elasticsearch后端按距离排序,而不是地理点字段错误,elasticsearch,django-haystack,elasticsearch,Django Haystack" /> elasticsearch Django Haystack通过Elasticsearch后端按距离排序,而不是地理点字段错误,elasticsearch,django-haystack,elasticsearch,Django Haystack" />

elasticsearch Django Haystack通过Elasticsearch后端按距离排序,而不是地理点字段错误

elasticsearch Django Haystack通过Elasticsearch后端按距离排序,而不是地理点字段错误,elasticsearch,django-haystack,elasticsearch,Django Haystack,我使用的是django 1.4、django haystack 2.0和Elasticsearch 0.19.1,我有这样一个搜索索引: from haystack import indexes from core.models import Project class ProjectIndex(indexes.RealTimeSearchIndex, indexes.Indexable): text = indexes.CharField(document=True, use_tem

我使用的是django 1.4、django haystack 2.0和Elasticsearch 0.19.1,我有这样一个搜索索引:

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
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)
项目模型如下:

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
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)
因此,我想按距离特定坐标从近到远查询项目对象:

....
location = Point(project.longitude, project.latitude)
projects = SearchQuerySet().models(Project).distance('location', location).order_by('distance')
但我得到了一个错误:

使用“:”查询Elasticsearch失败:返回的非正常状态代码(500),其中包含u'SearchPhaseExecutionException[执行阶段[query]失败,完全失败;shardFailures{[JMUKHKDTX-bo9DhFJdtSw][skp][2]:QueryPhaseExecutionException[[skp][2]:查询[filtered(ConstantCore)(未删除)(缓存(QueryRapperFilter(django-ct:core.projectаа]))->缓存(_type:modelresult)],来自[0],大小[10],排序[]:查询失败[未能执行主查询];嵌套:ElasticSearchillegargumentException[字段[位置]不是地理点字段];}{[jmUkmHkDTX-bo9DhFJdtSw][skp][4]:QueryPhaseExecutionException[[skp][4]:查询[已过滤(ConstantCore)(未删除)(缓存(QueryRapperFilter(django_ct:core.project(()(()((类型:modelresult)))->缓存((类型:modelresult)),从[0],大小[10],排序[]:查询失败[未能执行主查询];嵌套:ElasticSearchIllegalArgumentException[字段[位置]不是地理点字段];}]


有什么问题?

可能是位置字段的“类型”方面映射错误。这可能是由于用于映射的api造成的。映射中的某些方面可以更改,但“类型”方面不能更改字段的类型。因此,您必须使用geo_point类型的location字段创建一个新映射,并重新为您的文档编制索引。

可能是位置字段的“类型”方面映射错误。这可能是由于您用于映射的api造成的。映射中的某些方面可以更改,但不能更改“类型”一个字段的方面。因此,您必须使用geo_point类型的location字段创建一个新映射,并重新索引您的文档。

我清理了索引并创建了在中手动解释的模式,然后我使用
python manage.py update_index
更新了索引,然后问题就解决了。谢谢!现在将映射文档链接放到上面的注释404s中(2年后)。当前链接是:我清理了我的索引并创建了在中手动解释的架构,然后我使用
python manage.py update_index
更新了索引,问题已经解决。谢谢!现在将映射文档链接放到上面的评论404s中(2年后)。当前链接是: