-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Labels
Description
By enabling the Elasticsearch Highlighting feature, we can show previews of the context in which a search term matched, with the terms themselves visually highlighted.
For example, the following query:
{
"query": {
"match": {
"full_text": "science"
}
},
"size": 1,
"_source": false,
"highlight": {
"fields": {
"full_text": {
"pre_tags": [
"<b>"
],
"post_tags": [
"</b>"
]
}
}
}
}
executed with:
curl -XPOST https://cb-elasticsearch.derekenos.com:9200/moscon/_search -H "content-type: application/json" -d '{"query":{"match":{"full_text":"science"}},"size":1,"_source":false,"highlight":{"fields":{"full_text":{"pre_tags":["<b>"],"post_tags":["</b>"]}}}}'
yields the response:
{
"took": 170,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 22,
"relation": "eq"
},
"max_score": 0.047733817,
"hits": [
{
"_index": "moscon",
"_type": "_doc",
"_id": "moscon19-1997_000",
"_score": 0.047733817,
"highlight": {
"full_text": [
". here as our author and\n\n<b>science</b> guests of honor.",
"As a costumer, Betty has won scads of awards at <b>science</b> fiction costume events.",
"She works at the Owen <b>Science</b> & Engineering Library at WSU.",
"He is also the editor of a . new <b>science</b> fiction magazine, Tomorrow.",
"MosCon XIX Program Book\n\n17\n\nChanges in <b>Science</b>: <b>Science</b> Guest of Honor Poul Anderson has spent a long"
]
}
}
]
}
}
With the formatted snippets looking like this:
. here as our author and
science guests of honor.
As a costumer, Betty has won scads of awards at science fiction costume events.
She works at the Owen Science & Engineering Library at WSU.
He is also the editor of a . new science fiction magazine, Tomorrow.
MosCon XIX Program Book
17
Changes in Science: Science Guest of Honor Poul Anderson has spent a long