What is the Highlight API in Elasticsearch?

Answer

The Highlight API returns snippets of text from matched fields with the search terms wrapped in HTML tags (by default <em>), so you can display context around the match in your search results UI — similar to how Google shows bold terms in search snippets. Add a highlight section to your search request: {"highlight": {"fields": {"content": {}}}}. The response includes a highlight object per document with arrays of highlighted snippets. You can customize the pre/post tags, the number of fragments, and the fragment size. Elasticsearch offers three highlighter implementations: unified (default), plain, and fvh (fast vector highlighter, requires term vectors).