If you want to highlight search keywords in query results, you can use example below. For more information, read Highlighting and Highlighting Our Searches pages.


Query


This example uses "Plain highlighter" option which could be slower compared to other options so you better visit links above to choose the best one for your case.


curl -XGET "http://127.0.0.1:9203/_search?post_dev" -d'
{
"query": {
"match": {
"title": {
"query": "Title"
}
}
},
"highlight": {
"pre_tags": [
"<em>"
],
"post_tags": [
"</em>"
],
"tags_schema": "styled",
"fields": {
"title": {

}
}
},
"sort": [
{
"_score": {
"order": "asc"
}
}
],
"from": "0",
"size": "10"
}'

Result


{
"took": 6,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 2206,
"max_score": null,
"hits": [
{
"_index": "post_dev",
"_type": "post",
"_id": "9",
"_score": 1.1041983,
"_source": {
"id": 9,
"title": "Title 3",
"description": "Desc 2"
},
"highlight": {
"title": [
"<em class=\"hlt1\">Title</em> 3"
]
},
"sort": [
1.1041983
]
},
{
"_index": "post_dev",
"_type": "post",
"_id": "30",
"_score": 1.1041983,
"_source": {
"id": 30,
"title": "Title 2",
"description": "Desc 2",

},
"highlight": {
"title": [
"<em class=\"hlt1\">Title</em> 2"
]
},
"sort": [
1.1041983
]
}
}
}
}