Elasticsearch-DSL(highlight) 004

一般使用highlight_options函数设置高亮:函数

s = s.highlight_options(order='score')

使用highlight_options函数也是能够为单独的字段设置高亮:code

s = s.highlight('title')
# or, including parameters:
s = s.highlight('title', fragment_size=50)

fragement用来指定高亮字段的最大字符长度。it

输出高亮字段:io

response = s.execute()
for hit in response:
    for fragment in hit.meta.highlight.title:
        print(fragment)
相关文章
相关标签/搜索