Highlighting matches in fields
Adding a test document
PUT /highlighting/_doc/1
{
"description": "Let me tell you a story about Elasticsearch. It's a full-text search engine that is built on Apache Lucene. It's really easy to use, but also packs lots of advanced features that you can use to tweak its searching capabilities. Lots of well-known and established companies use Elasticsearch, and so should you!"
}
Highlighting matches within the description
field
GET /highlighting/_search
{
"_source": false,
"query": {
"match": { "description": "Elasticsearch story" }
},
"highlight": {
"fields": {
"description" : {}
}
}
}
Specifying a custom tag
GET /highlighting/_search
{
"_source": false,
"query": {
"match": { "description": "Elasticsearch story" }
},
"highlight": {
"pre_tags": [ "<strong>" ],
"post_tags": [ "</strong>" ],
"fields": {
"description" : {}
}
}
}