Skip to main content

Highlighting

This example uses the long form of the query. Besides the query itself, it sets highlight to ask Elasticsearch for the text fragments of the property description which matched the full text search for “lily”. The options pre_tags and post_tags wrap each match, encoder escapes the stored text, and number_of_fragments limits the number of fragments per element. The search is restricted to plants, and only the first three results are returned.

curl -X POST \
-H 'Authorization: Bearer secret-token:PIPeJGUt7c00ENn8a5uDlc' \
-H 'Content-Type: application/json' \
-d '{
"debug": true,
"steps": [
{
"type": "elasticsearch-query-dsl-mixin",
"query": {
"query": {
"match": {
"description": "lily"
}
},
"highlight": {
"encoder": "html",
"pre_tags": [
"<mark>"
],
"post_tags": [
"</mark>"
],
"fields": {
"description": {
"number_of_fragments": 1
}
}
}
},
"parameters": {
"nodeTypes": [
"Plant"
],
"pageSize": 3
}
},
{
"type": "element-hydration"
}
]
}' \
https://api.example.com/search
  • Flame Lily

    Common names include flame lily, climbing lily, creeping lily, glory lily, gloriosa lily, tiger claw,

  • Red Hot Poker

    The leaves are reminiscent of a lily, and the flowerhead can reach up to 1.5 m (5 ft) in height.

  • Lily

    Lilium candidum, the Madonna lily or white lily, is a plant in the true lily family.

[
{
"input": {
"type": "elasticsearch-query-dsl-mixin",
"query": {
"query": {
"match": {
"description": "lily"
}
},
"highlight": {
"pre_tags": [
"<mark>"
],
"post_tags": [
"</mark>"
],
"fields": {
"description": {
"number_of_fragments": 1
}
},
"encoder": "html"
}
},
"parameters": {
"nodeTypes": [
"Plant"
],
"pageSize": 3,
"stepResults": []
}
},
"step-handler": "elasticsearch-query-dsl-mixin (App\\EventSystem\\SearchStep\\EventListener\\ElasticsearchQueryDslMixinSearchStepEventListener)",
"start": 1796473117.510945,
"indices": "node_plant",
"combinedQuery": {
"_source": [
"_id"
],
"from": 0,
"size": 3,
"query": {
"bool": {
"must": [
{
"match": {
"description": "lily"
}
}
],
"filter": [
{
"bool": {
"should": [
{
"terms": {
"_groupsWithSearchAccess.keyword": []
}
},
{
"term": {
"_usersWithSearchAccess.keyword": {
"value": "02IiNr0GOoKiPMM5A0eq9jHk2upaJezsVtWjL"
}
}
}
],
"minimum_should_match": 1
}
}
]
}
},
"highlight": {
"pre_tags": [
"<mark>"
],
"post_tags": [
"</mark>"
],
"fields": {
"description": {
"number_of_fragments": 1
}
},
"encoder": "html"
}
},
"end": 1796473117.520669,
"duration": 0.009724
},
{
"input": {
"type": "element-hydration",
"query": null,
"parameters": {
"stepResults": [
{
"elements": [
{
"id": "02IiNr0GOoKiPMLPDlPbKrlR4vnBQsvSBSkU5",
"type": "Plant",
"metadata": {
"score": 4.001134,
"highlight": {
"description": [
"Common names include flame <mark>lily</mark>, climbing <mark>lily</mark>, creeping <mark>lily</mark>, glory <mark>lily</mark>, gloriosa <mark>lily</mark>, tiger claw,"
]
}
}
},
{
"id": "02IiNr0GOoKiPMN3kwX8zU4CDN8SlR7WlvzLO",
"type": "Plant",
"metadata": {
"score": 3.2452915,
"highlight": {
"description": [
"The leaves are reminiscent of a <mark>lily</mark>, and the flowerhead can reach up to 1.5 m (5 ft) in height."
]
}
}
},
{
"id": "02IiNr0GOoKiPMLO9dQSP9Mmvy5E3YmZXDsBP",
"type": "Plant",
"metadata": {
"score": 3.0498557,
"highlight": {
"description": [
"Lilium candidum, the Madonna <mark>lily</mark> or white <mark>lily</mark>, is a plant in the true <mark>lily</mark> family."
]
}
}
}
],
"totalHits": 8,
"maxScore": 4.001134
}
]
}
},
"step-handler": "element-hydration (App\\EventSystem\\SearchStep\\EventListener\\ElementHydrationSearchStepEventListener)",
"start": 1796473117.52098,
"accessibleElementIds": [
"02IiNr0GOoKiPMLPDlPbKrlR4vnBQsvSBSkU5",
"02IiNr0GOoKiPMN3kwX8zU4CDN8SlR7WlvzLO",
"02IiNr0GOoKiPMLO9dQSP9Mmvy5E3YmZXDsBP"
],
"end": 1796473117.531925,
"duration": 0.010945
}
]
{
"type": "_SearchResultResponse",
"results": [
{
"type": "Plant",
"id": "02IiNr0GOoKiPMLPDlPbKrlR4vnBQsvSBSkU5",
"data": {
"images": [
{
"description": "",
"imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/f/fe/Flame_lily.png",
"imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/f/fe/Flame_lily.png/500px-Flame_lily.png",
"link": "https://en.wikipedia.org/wiki/File:Flame_lily.png"
},
{
"description": "Gloriosa superba at Mabvuku, Harare, Zimbabwe",
"imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/b/bc/Gloriosa_superba_1.jpg",
"imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/b/bc/Gloriosa_superba_1.jpg/960px-Gloriosa_superba_1.jpg",
"link": "https://en.wikipedia.org/wiki/File:Gloriosa_superba_1.jpg"
}
],
"hasFile": true,
"name": "Flame Lily",
"scenario": "general.botanicExample",
"scientificName": "G. superba",
"link": "https://en.wikipedia.org/wiki/Gloriosa_superba",
"description": "Gloriosa superba is a species of flowering plant in the family Colchicaceae. Common names include flame lily, climbing lily, creeping lily, glory lily, gloriosa lily, tiger claw, and fire lily.",
"createdAt": "2026-12-05T12:16:05+00:00",
"updatedAt": "2026-12-05T12:16:05+00:00"
},
"file": {
"contentLength": 90681,
"extension": "jpg",
"mimeType": "image/jpeg",
"hash": {
"sha256": "72e3e3770db795b2f04f0b5bb0be43e74df70de4faa0bf83a706bbde29e4ea0b"
}
},
"metadata": {
"score": 4.001134,
"highlight": {
"description": [
"Common names include flame <mark>lily</mark>, climbing <mark>lily</mark>, creeping <mark>lily</mark>, glory <mark>lily</mark>, gloriosa <mark>lily</mark>, tiger claw,"
]
}
}
},
{
"type": "Plant",
"id": "02IiNr0GOoKiPMN3kwX8zU4CDN8SlR7WlvzLO",
"data": {
"images": [
{
"description": "Red-hot poker plants (Kniphofia uvaria) on the shore of Lake Jindabyne, New South Wales, Australia.",
"imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/c/c1/Kniphofia_uvaria_close.JPG",
"imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Kniphofia_uvaria_close.JPG/960px-Kniphofia_uvaria_close.JPG",
"link": "https://en.wikipedia.org/wiki/File:Kniphofia_uvaria_close.JPG"
}
],
"hasFile": true,
"name": "Red Hot Poker",
"scenario": "general.botanicExample",
"scientificName": "K. uvaria",
"link": "https://en.wikipedia.org/wiki/Kniphofia_uvaria",
"description": "Kniphofia uvaria is a species of flowering plant in the family Asphodelaceae, commonly known as tritomea, torch lily, or red hot poker, due to the shape and color of its inflorescence. The leaves are reminiscent of a lily, and the flowerhead can reach up to 1.5 m (5 ft) in height. There are many varieties of torch lily, and they bloom at different times during the growing season. The flowers are red, orange, and yellow.",
"createdAt": "2026-12-05T12:16:05+00:00",
"updatedAt": "2026-12-05T12:16:05+00:00"
},
"file": {
"contentLength": 123686,
"extension": "jpg",
"mimeType": "image/jpeg",
"hash": {
"sha256": "a0f461e0383bc5b4518a43e1ac76060612c7e87bf420f9a6bbbe5231012108fe"
}
},
"metadata": {
"score": 3.2452915,
"highlight": {
"description": [
"The leaves are reminiscent of a <mark>lily</mark>, and the flowerhead can reach up to 1.5 m (5 ft) in height."
]
}
}
},
{
"type": "Plant",
"id": "02IiNr0GOoKiPMLO9dQSP9Mmvy5E3YmZXDsBP",
"data": {
"images": [
{
"description": "Lilium candidum, Israel",
"imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/c/cc/ShoshanTzachor-2-wiki-Zachi-Evenor.jpg",
"imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/c/cc/ShoshanTzachor-2-wiki-Zachi-Evenor.jpg/500px-ShoshanTzachor-2-wiki-Zachi-Evenor.jpg",
"link": "https://en.wikipedia.org/wiki/File:ShoshanTzachor-2-wiki-Zachi-Evenor.jpg"
},
{
"description": "Photo of Lilium candidum at VanDusen Botanical Garden",
"imageLinkFull": "https://upload.wikimedia.org/wikipedia/commons/3/30/Lilium_candidum_1.jpg",
"imageLinkThumbnail": "https://upload.wikimedia.org/wikipedia/commons/thumb/3/30/Lilium_candidum_1.jpg/960px-Lilium_candidum_1.jpg",
"link": "https://en.wikipedia.org/wiki/File:Lilium_candidum_1.jpg"
}
],
"hasFile": true,
"name": "Lily",
"scenario": "general.botanicExample",
"scientificName": "L. candidum",
"link": "https://en.wikipedia.org/wiki/Lilium_candidum",
"description": "Lilium candidum, the Madonna lily or white lily, is a plant in the true lily family. It is native to the Balkans and Middle East, and naturalized in other parts of Europe, including France, Italy, and Ukraine, and in North Africa, the Canary Islands, Mexico, and other regions. It has been cultivated since antiquity, for at least 3,000 years, and has great symbolic value since then for many cultures. It is susceptible to several virus diseases common to lilies, and especially to Botrytis fungus. One technique to avoid problems with viruses is to grow plants from seed instead of bulblets.",
"createdAt": "2026-12-05T12:16:05+00:00",
"updatedAt": "2026-12-05T12:16:05+00:00"
},
"file": {
"contentLength": 115168,
"extension": "jpg",
"mimeType": "image/jpeg",
"hash": {
"sha256": "ee066b93ae72c719f863a428f03c86ecd28e52818528eacf4d4e32acb4b4b37c"
}
},
"metadata": {
"score": 3.0498557,
"highlight": {
"description": [
"Lilium candidum, the Madonna <mark>lily</mark> or white <mark>lily</mark>, is a plant in the true <mark>lily</mark> family."
]
}
}
}
],
"debug": [
{
"input": {
"type": "elasticsearch-query-dsl-mixin",
"query": {
"query": {
"match": {
"description": "lily"
}
},
"highlight": {
"pre_tags": [
"<mark>"
],
"post_tags": [
"</mark>"
],
"fields": {
"description": {
"number_of_fragments": 1
}
},
"encoder": "html"
}
},
"parameters": {
"nodeTypes": [
"Plant"
],
"pageSize": 3,
"stepResults": []
}
},
"step-handler": "elasticsearch-query-dsl-mixin (App\\EventSystem\\SearchStep\\EventListener\\ElasticsearchQueryDslMixinSearchStepEventListener)",
"start": 1796473117.510945,
"indices": "node_plant",
"combinedQuery": {
"_source": [
"_id"
],
"from": 0,
"size": 3,
"query": {
"bool": {
"must": [
{
"match": {
"description": "lily"
}
}
],
"filter": [
{
"bool": {
"should": [
{
"terms": {
"_groupsWithSearchAccess.keyword": []
}
},
{
"term": {
"_usersWithSearchAccess.keyword": {
"value": "02IiNr0GOoKiPMM5A0eq9jHk2upaJezsVtWjL"
}
}
}
],
"minimum_should_match": 1
}
}
]
}
},
"highlight": {
"pre_tags": [
"<mark>"
],
"post_tags": [
"</mark>"
],
"fields": {
"description": {
"number_of_fragments": 1
}
},
"encoder": "html"
}
},
"end": 1796473117.520669,
"duration": 0.009724
},
{
"input": {
"type": "element-hydration",
"query": null,
"parameters": {
"stepResults": [
{
"elements": [
{
"id": "02IiNr0GOoKiPMLPDlPbKrlR4vnBQsvSBSkU5",
"type": "Plant",
"metadata": {
"score": 4.001134,
"highlight": {
"description": [
"Common names include flame <mark>lily</mark>, climbing <mark>lily</mark>, creeping <mark>lily</mark>, glory <mark>lily</mark>, gloriosa <mark>lily</mark>, tiger claw,"
]
}
}
},
{
"id": "02IiNr0GOoKiPMN3kwX8zU4CDN8SlR7WlvzLO",
"type": "Plant",
"metadata": {
"score": 3.2452915,
"highlight": {
"description": [
"The leaves are reminiscent of a <mark>lily</mark>, and the flowerhead can reach up to 1.5 m (5 ft) in height."
]
}
}
},
{
"id": "02IiNr0GOoKiPMLO9dQSP9Mmvy5E3YmZXDsBP",
"type": "Plant",
"metadata": {
"score": 3.0498557,
"highlight": {
"description": [
"Lilium candidum, the Madonna <mark>lily</mark> or white <mark>lily</mark>, is a plant in the true <mark>lily</mark> family."
]
}
}
}
],
"totalHits": 8,
"maxScore": 4.001134
}
]
}
},
"step-handler": "element-hydration (App\\EventSystem\\SearchStep\\EventListener\\ElementHydrationSearchStepEventListener)",
"start": 1796473117.52098,
"accessibleElementIds": [
"02IiNr0GOoKiPMLPDlPbKrlR4vnBQsvSBSkU5",
"02IiNr0GOoKiPMN3kwX8zU4CDN8SlR7WlvzLO",
"02IiNr0GOoKiPMLO9dQSP9Mmvy5E3YmZXDsBP"
],
"end": 1796473117.531925,
"duration": 0.010945
}
]
}
Access-Control-Allow-Headers: Authorization, Content-Type, Prefer
Access-Control-Allow-Methods: OPTIONS, POST
Access-Control-Allow-Origin: *
Access-Control-Expose-Headers: Preference-Applied
Allow: OPTIONS, POST
Cache-Control: no-cache, private
Content-Type: application/json; charset=utf-8
Date: Thu, 03 Dec 2026 12:24:49 GMT
Transfer-Encoding: chunked
Vary: Prefer, Accept-Encoding
X-Powered-By: Ember Nexus API

The first tab lists each plant with its highlighted description, the other tabs show the raw response. The hydrated elements contain the highlights in metadata.highlight.description. Next to it, metadata.score contains the score of the element.

Note: Highlights contain stored text. If you render them as HTML like the list above, add "encoder": "html" to the highlight options, so that Elasticsearch escapes the text and only the tags are markup. Fields which start with an underscore or a wildcard are rejected.