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).
Previous
What is search_after pagination in Elasticsearch?
Next
What is the difference between nested objects and the object type in Elasticsearch?
More Elasticsearch Questions
View all →- Intermediate What is the difference between query context and filter context in Elasticsearch?
- Intermediate What is a bool query in Elasticsearch?
- Intermediate What are aggregations in Elasticsearch?
- Intermediate What is the difference between text and keyword field types?
- Intermediate What are index templates and component templates in Elasticsearch?