Search snippets let you display the portion of a document that matches a user’s query, with matched terms highlighted. This helps users quickly evaluate whether a result is relevant without reading the full document content. Meilisearch provides two complementary features for this: highlighting wraps matched terms in tags, and cropping trims long text fields to show only the relevant portion around matched terms.Documentation 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.
Highlighting matched terms
UseattributesToHighlight to specify which fields should have matched terms wrapped in highlight tags. Set it to ["*"] to highlight all displayed attributes.
_formatted object in each hit. Inside _formatted, matched terms are wrapped in <em> tags by default:
Custom highlight tags
UsehighlightPreTag and highlightPostTag to replace the default <em> tags with custom markup:
Cropping long text fields
UseattributesToCrop to trim long text fields so only the portion around matched terms is returned. This is especially useful for fields like descriptions or article bodies.
_formatted object contains the cropped text:
Crop parameters
| Parameter | Default | Description |
|---|---|---|
attributesToCrop | null | Array of attributes to crop. Use ["*"] for all displayed attributes. |
cropLength | 10 | Maximum number of words in the cropped text. |
cropMarker | "..." | String placed at the beginning or end of cropped text to indicate truncation. |
Custom crop length per attribute
You can set a specific crop length for individual attributes by appending:length to the attribute name:
Combining highlighting and cropping
For the best user experience, use both features together. This gives you a short, relevant snippet with matched terms visually emphasized:_formatted response combines both:
For the full parameter reference, see the search API reference.