I am using elasticsearch-dsl in my django project. Elasticsearch is totally new for me and at some point i got this error: error
So i started debugging and removing some part of my code. But here i am my code has become extremely simple but i still don't know why i get this error.
The code:
import re
from django.conf import settings
from elasticsearch_dsl.query import Bool, Match, MatchPhrase, Nested
from .documents import RubricPageDocument
def _build_match_query(query, field):
if len(query) <= 4:
return Match(**{field: {'query': query}})
if re.match('^".*"$', query):
return MatchPhrase(**{field: {'query': query}})
return Match(**{field: {'query': query, 'fuzziness': 'AUTO'}})
def search_query_in_rubric_pages(query):
q_title = _build_match_query(query, 'title')
q = q_title
s = RubricPageDocument.search().query(q)
response = s.execute() # error raise on this line
return [_format_hit(hit, 'rubric') for hit in response]
def search_query(query):
"""
search in elastic search index for rubric pages
* query (str): the query
"""
page_hits = search_query_in_rubric_pages(query)
return {
'hits': page_hits,
}
Please help me