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

标签 elasticsearch django-haystack

我正在使用 django 1.4、django-haystack 2.0 和 Elasticsearch 0.19.1 我有一个这样的 SearchIndex:

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)

所以我想通过从近到远的距离特定坐标来查询Project对象:

....
location = Point(project.longitude, project.latitude)
projects = SearchQuerySet().models(Project).distance('location', location).order_by('distance')

但我收到此错误:

无法使用“:”查询 Elasticsearch:返回非正常状态代码 (500),其中包含 u'SearchPhaseExecutionException[无法执行阶段 [查询],完全失败; 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[]: 查询失败[执行主查询失败]];嵌套:ElasticSearchIllegalArgumentException[field [location] 不是 geo_point 字段]; }{[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[]: 查询失败[执行主查询失败]];嵌套:ElasticSearchIllegalArgumentException[field [location] 不是 geo_point 字段]; }]'。

出了什么问题?

最佳答案

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

关于elasticsearch - Django Haystack 通过 Elasticsearch 后端按距离排序,而不是 geo_point 字段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10105693/

相关文章:

linux - curl 命令在 bash 脚本中不起作用

solr - django-haystack 不会索引我的数据

django - 搜索查询集的 __contains 过滤器有用吗?

python - 如何从外部脚本更新 haystack 的索引?

python - Django 搜索 : Setting Haystack_Default_Operator = 'OR' has no effect

nosql - 在 Elastic Search 上查询多级嵌套字段

Elasticsearch 动态映射与地理点

django - 干草堆 : KeyError in the elasticsearch_backend module

elasticsearch - 如何在所有文档中查询与键关联的值?

elasticsearch - elasticsearch和kibana在不同机器上的设置