I have a simple elasticsearch-dsl-py code. Everything is fine, even tags, except number_of_fragments. Response continuing giving multiply highlights for single word.
def name_autocomplete(q):
multi_match = MultiMatch(query=q, fields=ngram_fields, fuzziness='AUTO', tie_breaker=1)
s = s.query(multi_match)[0:5] \
.highlight_options(pre_tags='<b>', post_tags='</b>',
number_of_fragments=1, # This is not working
order='score') \
.highlight('name.ngram') \
.execute()
response_dict = s.to_dict()
return Response(response_dict)
What am I doing wrong?
ADDED:
Analyzer:
edge_ngram_completion = analyzer(
"edge_ngram_completion",
tokenizer=tokenizer('trigram', 'nGram', min_gram=3, max_gram=4),
filter=["lowercase"]
)
Document:
class TerminalDocument(Document):
"""Document Elasticsearch document."""
id = fields.IntegerField(attr='id')
name = fields.TextField(
fields={
'suggest': fields.TextField(analyzer=ascii_fold),
'ngram': fields.TextField(analyzer=edge_ngram_completion)
}
)
Example of hidhlighting for foobar:
"<b>foo</b>something<b>bar</b>"