Highlighting wraps matched query terms in HTML tags so your frontend can visually emphasize them. Cropping trims long text fields to show only the relevant portion around matched terms. Both features work through search parameters and return their results in theDocumentation Index
Fetch the complete documentation index at: https://www.meilisearch.com/docs/llms.txt
Use this file to discover all available pages before exploring further.
_formatted object of each hit.
Highlight specific attributes
UseattributesToHighlight to specify which fields should have matched terms wrapped in tags:
_formatted object wrapped in <em> tags:
Highlight all attributes
SetattributesToHighlight to ["*"] to highlight matched terms across all displayed attributes:
attributesToHighlight highlights matches within any attribute you list, even attributes that are not part of searchableAttributes. Meilisearch does not produce new matches in non-searchable fields, but if the query term happens to appear verbatim in one of those fields, it will still be wrapped in highlight tags.Custom highlight tags
Replace the default<em> tags with any markup using highlightPreTag and highlightPostTag:
Crop long text fields
UseattributesToCrop to trim long fields and show only the portion around the matched terms:
Crop parameters reference
| Parameter | Type | Default | Description |
|---|---|---|---|
attributesToCrop | Array of strings | null | Attributes to crop. Use ["*"] for all displayed attributes. |
cropLength | Integer | 10 | Maximum number of words in the cropped result. |
cropMarker | String | "..." | String inserted at the beginning or end of cropped text. |
cropLength counts every word in the returned snippet, including query terms and stop words. For example, if cropLength is 2 and you search for shifu, the cropped value might look like "…Shifu informs…", containing two words in total (the query term plus one surrounding word).Crop markers are only inserted where content has been removed. If the cropped snippet begins at the first word of the field, no marker is added to the start; likewise, no marker is added to the end when the snippet reaches the end of the field.
Per-attribute crop length
Override the globalcropLength for specific attributes by appending :length to the attribute name:
Custom crop marker
Replace the default"..." truncation marker:
Combine highlighting and cropping
For the best user experience, use both features together to show short, relevant snippets with visually emphasized matches:For the full parameter reference, see the search API reference.