API version: 0.3.0

---

# Highlighting

This example uses the [long form](/reference/search/elasticsearch-query-dsl-mixin.md#step-query) 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.

```bash
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
```

##### Response Body

```json
{
  "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_supe...",
            "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 fl...",
        "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>..."
          ]
        }
      }
    },
    {
      "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...",
            "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 trit...",
        "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) i..."
          ]
        }
      }
    },
    {
      "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/500...",
            "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_candidu...",
            "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...",
        "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 <m..."
          ]
        }
      }
    }
  ],
  "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\\ElasticsearchQueryDslMixinSe...",
      "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>..."
                      ]
                    }
                  }
                },
                {
                  "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) i..."
                      ]
                    }
                  }
                },
                {
                  "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 <m..."
                      ]
                    }
                  }
                }
              ],
              "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
    }
  ]
}
```

##### Response Headers

```http
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](/reference/search/element-hydration.md#metadata) 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.

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [Parameterized search](/reference/search/elasticsearch-query-dsl-mixin/parameterized-search.md)

Next: [Sorting](/reference/search/elasticsearch-query-dsl-mixin/sorting.md)
