通常使用highlight_options函数设置高亮:
s = s.highlight_options(order='score')
使用highlight_options函数也是可以为单独的字段设置高亮:
s = s.highlight('title')
# or, including parameters:
s = s.highlight('title', fragment_size=50)
fragement用来指定高亮字段的最大字符长度。
输出高亮字段:
response = s.execute()
for hit in response:
for fragment in hit.meta.highlight.title:
print(fragment)