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?