elasticsearch设置高亮Highlighting
链接 To set common attributes for highlighting use the highlight_options method:
s = s.highlight_options(order='score')
Enabling highlighting for individual fields is done using the highlight method:
s = s.highlight('title')
or, including parameters:
s = s.highlight('title', fragment_size=50)
The fragments in the response will then be available on each Result object as .meta.highlight.FIELD which will contain the list of fragments:
response = s.execute()
for hit in response:
for fragment in hit.meta.highlight.title:
print(fragment)