Django_elasticsearch_dsl -RequestError(400, 'search_phase_execution_exception', 'failed to create query: For input string: )
Я пытаюсь выполнить поиск с помощью Elasticsearch, используя django_elasticsearch_dsl и 'django_elasticsearch_dsl_drf', но получаю RequestError(400, 'search_phase_execution_exception', 'failed to create query: 'Для входной строки: "MM"'). Я могу искать, если мой ввод является целым числом или float, но я не могу искать для строки. Вот мой файл document.py:-
from django_elasticsearch_dsl import (
Document ,
fields,
Index,
)
#from .models import ElasticDemo
from .models import Course
#PUBLISHER_INDEX = Index('elastic_demo')
PUBLISHER_INDEX = Index('courses') #Name of the database that we are making
PUBLISHER_INDEX.settings(
number_of_shards=1,
number_of_replicas=1
)
@PUBLISHER_INDEX.doc_type
class CourseDocument(Document):
id = fields.IntegerField(attr='id')
#fielddata=True
course_index = fields.IntegerField(
fields={
'raw': fields.IntegerField(analyzer='keyword'),
}
)
Code = fields.TextField(
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
Title = fields.TextField(
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
TotalCredits = fields.FloatField(
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
Description = fields.TextField(
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
department = fields.TextField(
fields={
'raw': fields.TextField(analyzer='keyword'),
}
)
class Django(object):
model = Course
Вот мой views.py
class CourseDocumentView(DocumentViewSet):
document = CourseDocument
serializer_class = CourseSerializer
lookup_field = 'id'
filter_backends = [
FilteringFilterBackend,
OrderingFilterBackend,
CompoundSearchFilterBackend,
#DefaultOrderingFilterBackend,
SearchFilterBackend,
]
search_fields = (
'Code',
'Title',
'TotalCredits',
'Description',
'department',
)
multi_match_search_fields = (
'Code',
'Title',
'TotalCredits',
'Description',
'department',
)
filter_fields = {
'Code' : 'Code',
'Title' : 'Title',
'TotalCredits' : 'TotalCredits',
'Description': 'Description',
'department': 'department' ,
}
ordering_fields = {
'Code':None,
'TotalCredits':None,
'Title':None,
}
ordering = ( 'id' , )
pagination_class = QueryFriendlyPageNumberPagination
А вот мой сериализатор:
import json
from .models import Course
from rest_framework import serializers
from django_elasticsearch_dsl_drf.serializers import DocumentSerializer
from .documents import *
class CourseSerializer(DocumentSerializer):
class Meta(object):
"""Meta options"""
model = Course
document = CourseDocument
fields = (
'course_index',
'Code',
'Title',
'TotalCredits',
'Description',
'department',
)
def get_location(self, obj):
"""Represent location value."""
try:
return obj.location.to_dict()
except:
return {}
Я новичок в elasticsearch. Любая помощь будет высоко оценена