"BulkIndexError at /admin/books/address/add/" Django_rest_framework + ElasticSearch

I am trying to implement Elastic Search with django rest framework. I have implemented it without nested fields(Foreign Keys). But now stuck while trying to work with nested fields. I am following this documentation django-elasticsearch-dsl-drf.

В админпанели django я могу создать модель города и страны, но когда я создаю модель адреса, я получаю эту ошибку:

('1 document(s) failed to index.', [{'index': {'_index': 'address', '_type': '_doc', '_id': '7', 'status': 400, 'error': {'type': 'illegal_argument_exception', 'reason': 'The [standard] token filter has been removed.'}, 'data': {'id': 7, 'street': '20', 'house_number': '155', 'appendix': 'sonething', 'zip_code': '123', 'city': {'name': 'Lahore', 'info': 'this is my city', 'location': {'lat': Decimal('31.504828100000000'), 'lon': Decimal('74.323542500000000')}, 'country': {'name': 'Pakistan', 'info': 'this is my country', 'location': {'lat': Decimal('31.504828100000000'), 'lon': Decimal('74.323542500000000')}}}, 'location': {'lat': Decimal('31.5048281'), 'lon': Decimal('74.3235425')}}}}]).

Заранее спасибо за помощь и ваше дополнение к моим знаниям.

Я делюсь с вами своими файлами для лучшего понимания.

Models.py

Documents.py

Serializers.py

import json
from django_elasticsearch_dsl_drf.serializers import DocumentSerializer
from rest_framework import serializers
from .documents import PublisherDocument


class PublisherDocumentSerializer(DocumentSerializer):
    """Serializer for Publisher document."""

    location = serializers.SerializerMethodField()

    class Meta:
        """Meta options."""

        # Specify the correspondent document class
        document = PublisherDocument
        # Note, that since we're using a dynamic serializer,
        # we only have to declare fields that we want to be shown. If
        # somehow, dynamic serializer doesn't work for you, either extend
        # or declare your serializer explicitly.
        fields = (
            'id',
            'name',
            'address',
            'city',
            'state_province',
            'country',
            'website',
        )

    def get_location(self, obj):
        """Represent location value."""
        try:
            return obj.location.to_dict()
        except:
            return {}

Views.py:

from django_elasticsearch_dsl_drf.constants import (
    LOOKUP_FILTER_GEO_DISTANCE,
)
from django_elasticsearch_dsl_drf.filter_backends import (
    FilteringFilterBackend,
    OrderingFilterBackend,
    SearchFilterBackend,
    GeoSpatialFilteringFilterBackend,

)
from django_elasticsearch_dsl_drf.viewsets import DocumentViewSet

# Example app models
from .documents import PublisherDocument
from .serializers import PublisherDocumentSerializer
from rest_framework import generics
from .models import Publisher
from rest_framework.pagination import PageNumberPagination


class PublisherDocumentView(DocumentViewSet):
    """The PublisherDocument view."""

    document = PublisherDocument
    serializer_class = PublisherDocumentSerializer
    pagination_class = PageNumberPagination
    lookup_field = 'id'
    filter_backends = [
        FilteringFilterBackend,
        OrderingFilterBackend,
        SearchFilterBackend,
        GeoSpatialFilteringFilterBackend
    ]
    # Define search fields
    search_fields = (
        'name',
        'address',
        'city',
        'state_province',
        'country',
        'location'
    )
    # Define filtering fields
    filter_fields = {
        'id': None,
        'name': 'name.raw',
        'city': 'city.raw',
        'state_province': 'state_province.raw',
        'country': 'country.raw',
    }
    # Define ordering fields
    ordering_fields = {
        'id': None,
        'name': None,
        'city': None,
        'country': None,
    }
    # Specify default ordering
    ordering = ('id', 'name',)
    # Define geo-spatial filtering fields
    geo_spatial_filter_fields = {
        'location': {
            'lookups': [
                LOOKUP_FILTER_GEO_DISTANCE,
            ],
        },
    }

Решено В моем анализаторе возникла проблема. Я сделал следующие изменения в documents.py analyzer.

html_strip = analyzer(
    'html_strip',
    type="custom",
    tokenizer="standard",
    filter=["lowercase"],
    char_filter=["html_strip"]
)
Вернуться на верх