django-es / django-elasticsearch-dsl

This is a package that allows indexing of django models in elasticsearch with elasticsearch-dsl-py.
Other
1.01k stars 262 forks source link

geopoint #195

Open alaa-jaradat opened 5 years ago

alaa-jaradat commented 5 years ago

I am trying to map gis PointField to elastricsearch index but i am receiving this error: TypeError("Unable to serialize <Point object at 0x1fb67301990> (type: <class 'django.contrib.gis.geos.point.Point'>)",))

Does this library support this type of gis model field ?

My model.py: from django.db import models _from django.contrib.gis.db import models as gismodels from django.db.models import Manager as GeoManager

_class Places(models.Model): location = gis_models.PointField(srid=4326, null=True, blank=True)__

My documents.py:

_from django_elasticsearch_dsl import Document, fields from django_elasticsearchdsl.registries import registry

_from .models import Places @registry.registerdocument class PlacesDocument(Document): location = fields.GeoPointField()

class Index:
    name = 'places'

class Django:
    model = Places
DiogoMarques29 commented 5 years ago

Same problem here!

nortigo commented 5 years ago

For those who are interested, this is how I "fix" it:

@registry.register_document
class BusinessDocument(Document):
    geocoords = fields.GeoPointField()

    def prepare_geocoords(self, instance: Business) -> Dict:
        return {
            'lon': instance.geocoords.x,
            'lat': instance.geocoords.y
        }

Hope that'll help you.