-
Notifications
You must be signed in to change notification settings - Fork 134
Description
A bit of background
I am merely trying to run a request that will let me get some documents are located around a certain point. I keep getting that error from the dataset, and the issue eludes me...
I have been stuck on this issue for a while. Tried changing versions for each of the packages but to no avail..
Versions used
Django==4.1
django-elasticsearch-dsl==7.2.2
django-elasticsearch-dsl-drf==0.22.5
djangorestframework==3.13.1
elasticsearch==7.17.4
elasticsearch-dsl==7.3.0
Elastic search running in docker
elasticsearch:
restart: always
image: elasticsearch:7.17.4
environment:
- discovery.type=single-node
- xpack.security.enabled=false
env_file: .env.local
volumes:
- /usr/share/elasticsearch/data
ports:
- "9200:9200"
Documents and datasets
I am removing as much useless information as possible here:
Document
@registry.register_document
class PlaceDocument(Document):
class Index:
name = 'places'
settings = {
'number_of_shards': 1,
'number_of_replicas': 1
}
location = fields.GeoPointField(attr='location_field_indexing')
class Django:
model = Place
fields = [
'id',
]
related_models = [Service] # Optional: to ensure the Car will be re-saved when Service is updated
def get_instances_from_related(self, related_instance):
"""If related_models is set, define how to retrieve the Car instance(s) from the related model.
The related_models option should be used with caution because it can lead in the index
to the updating of a lot of items.
"""
if isinstance(related_instance, Service):
return related_instance.place
Serializer
class PlaceDocumentSimpleSerializer(DocumentSerializer):
"""Serializer for the Place document."""
class Meta:
"""Meta options."""
document = PlaceDocument
fields = (
'id',
'location'
)
View
class PlaceDocumentView(DocumentViewSet):
"""The PlaceDocumentView view."""
document = PlaceDocument
serializer_class = PlaceDocumentSimpleSerializer
lookup_field = 'id'
filter_backends = [
`GeoSpatialFilteringFilterBackend`,
]
# Define geo-spatial filtering fields
geo_spatial_filter_fields = {
'location': {
'lookups': [
LOOKUP_FILTER_GEO_DISTANCE,
],
},
}
Results
I am sure the indexing is done properly: when removing the GeoSpatialFilteringFilterBackend from the filter_backends, the request always returns a list of objects such as
[OrderedDict([('id', 1), ('location', {'lat': 1.0, 'lon': 1.0})])]
But when GeoSpatialFilteringFilterBackend is active I get
RequestError(400, 'search_phase_execution_exception', 'failed to find geo field [location]')
Possible solution
I am wondering if it is a version mismatch, but as I use Django 4, django-elasticsearch-dsl-drf seems to pass the tests (see this PR), and this is the only version compatible with django-elasticsearch-dsl....
Can anyone guide me towards some leads? I am not a ES guru and I have no idea how to proceed from there....
I tried going down to ES6 but nothing... And again, I am no sure how is DSL version-compatible....
BTW, it looks like the publisher view from the docs is also missing GeoSpatialFilteringFilterBackend
Thanks!