59285

Django Haystack order by distance by Elasticsearch backend, not a geo_point field error

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?

Answer1:

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.

Recommend

  • Why UICollectionView with UICollectionViewFlowLayout not show cells, but ask for size?
  • Categorize/Tag projects in Microsoft Dynamics CRM
  • Strange URL RewriteRule .htaccess Issue needs explaination
  • Laravel parent/children relationship on it's own model
  • Real Time Calculations?
  • Talend Open Studio - How to create brand new project
  • Can VS 2013 be installed on Server 2003 R2
  • Hibernate Filters on related table with MappedSuperClass
  • Updating indexes on placeholderfields in real time with django/haystack/solr
  • redirect user after update in class based view in django
  • Paramiko SSHException Channel Closed
  • How to implement simple validation in Scala
  • Python find continuous interesctions of intervals
  • How to override __call__ in celery on main?
  • Curried UDF - Pyspark
  • Python function to read variable length blocks of data from file while open
  • MRO with multiple inheritance in python
  • How to move an element within a structure, possibly with zippers?
  • @tailrec why does this method not compile with 'contains a recursive call not in tail position&
  • Fully customized Python Help Usage
  • SPARQL date range
  • Ruby 1.8.6 Array#uniq not removing duplicate hashes
  • Faster Way To Simultaneously Iterate Over Rolling Window Of Two Or More Numpy Arrays?
  • Django foreign key drop down
  • Does Apportable support to build library binary (.a/.so)?
  • Jenkins: FATAL: Could not initialize class hudson.util.ProcessTree$UnixReflection
  • Grails calculated field in SQL
  • Switching to Release Build causes runtime error in Web Reference
  • How to add date and time under each post in guestbook in google app engine
  • JSON with duplicate key names losing information when parsed
  • QuartzCore.framework for Mono Develop
  • Return words with double consecutive letters
  • Java static initializers and reflection
  • unknown Exception android
  • MATLAB: Piecewise function in curve fitting toolbox using fittype
  • Why is Django giving me: 'first_name' is an invalid keyword argument for this function?
  • Binding checkboxes to object values in AngularJs
  • Observable and ngFor in Angular 2
  • How can I use `wmic` in a Windows PE script?
  • Unable to use reactive element in my shiny app