2013-08-28 19:24:34 -04:00
[[search-request-highlighting]]
=== Highlighting
2017-06-09 08:09:57 -04:00
Highlighters allow you to produce highlighted snippets from one or more fields
in your search results.
2015-10-27 11:25:29 -04:00
The following is an example of the search request body:
2013-08-28 19:24:34 -04:00
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-08-28 19:24:34 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2017-01-17 06:20:03 -05:00
"match": { "content": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-08-28 19:24:34 -04:00
"highlight" : {
"fields" : {
2016-10-06 23:46:55 -04:00
"comment" : {}
2013-08-28 19:24:34 -04:00
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-08-28 19:24:34 -04:00
2016-10-06 23:46:55 -04:00
In the above case, the `comment` field will be highlighted for each
2013-08-28 19:24:34 -04:00
search hit (there will be another element in each search hit, called
`highlight`, which includes the highlighted fields and the highlighted
fragments).
2014-10-15 07:44:36 -04:00
[NOTE]
==================================
2013-08-28 19:24:34 -04:00
In order to perform highlighting, the actual content of the field is
2013-11-07 10:56:59 -05:00
required. If the field in question is stored (has `store` set to `true`
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
in the mapping) it will be used, otherwise, the actual `_source` will
2013-08-28 19:24:34 -04:00
be loaded and the relevant field will be extracted from it.
2014-10-15 07:44:36 -04:00
The `_all` field cannot be extracted from `_source`, so it can only
be used for highlighting if it mapped to have `store` set to `true`.
==================================
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
The field name supports wildcard notation. For example, using `comment_*`
2016-05-06 10:50:34 -04:00
will cause all <<text,text>> and <<keyword,keyword>> fields (and <<string,string>>
from versions before 5.0) that match the expression to be highlighted.
2016-05-06 07:20:28 -04:00
Note that all other fields will not be highlighted. If you use a custom mapper and want to
highlight on a field anyway, you have to provide the field name explicitly.
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
2017-06-09 08:09:57 -04:00
[[unified-highlighter]]
==== Unified Highlighter
2015-07-15 05:49:48 -04:00
2017-06-09 08:09:57 -04:00
The unified highlighter (which is used by default if no highlighter type is specified)
uses the Lucene Unified Highlighter.
This highlighter breaks the text into sentences and scores individual sentences as
if they were documents in this corpus, using the BM25 algorithm.
It also supports accurate phrase and multi-term (fuzzy, prefix, regex) highlighting.
2015-07-15 05:49:48 -04:00
2017-06-09 08:09:57 -04:00
===== Offsets Strategy
2015-07-15 05:49:48 -04:00
2017-06-09 08:09:57 -04:00
In order to create meaningful search snippets from the terms being queried,
a highlighter needs to know the start and end character offsets of each word
in the original text.
These offsets can be obtained from:
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
2017-06-09 08:09:57 -04:00
* The postings list (fields mapped as "index_options": "offsets").
* Term vectors (fields mapped as "term_vectors": "with_positions_offsets").
* The original field, by reanalysing the text on-the-fly.
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
2017-06-09 08:09:57 -04:00
====== Plain highlighting
This mode is picked when there is no other alternative.
It creates a tiny in-memory index and re-runs the original query criteria through
Lucene's query execution planner to get access to low-level match information on the current document.
This is repeated for every field and every document that needs highlighting.
====== Postings
If `index_options` is set to `offsets` in the mapping the `unified` highlighter
will use this information to highlight documents without re-analyzing the text.
It re-runs the original query directly on the postings and extracts the matching offsets
directly from the index limiting the collection to the highlighted documents.
This mode is faster on large fields since it doesn't require to reanalyze the text to be highlighted
and requires less disk space than term_vectors, needed for the fast vector
highlighting.
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
2016-10-06 23:46:55 -04:00
Here is an example of setting the `comment` field in the index mapping to allow for
2017-06-09 08:09:57 -04:00
highlighting using the postings:
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
[source,js]
--------------------------------------------------
2017-04-05 17:38:34 -04:00
PUT /example
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
{
2017-04-05 17:38:34 -04:00
"mappings": {
"doc" : {
"properties": {
"comment" : {
"type": "text",
"index_options" : "offsets"
}
}
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
}
2017-04-05 17:38:34 -04:00
}
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
}
--------------------------------------------------
2017-04-05 17:38:34 -04:00
// CONSOLE
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
2017-06-09 08:09:57 -04:00
====== Term Vectors
If `term_vector` information is provided by setting `term_vector` to
`with_positions_offsets` in the mapping then the `unified` highlighter
will automatically use the `term_vector` to highlight the field.
The `term_vector` highlighting is faster to highlight multi-term queries like
`prefix` or `wildcard` because it can access the dictionary of term for each document
but it is also usually more costly than using the `postings` directly.
Here is an example of setting the `comment` field to allow for
highlighting using the `term_vectors` (this will cause the index to be bigger):
[source,js]
--------------------------------------------------
PUT /example
{
"mappings": {
"doc" : {
"properties": {
"comment" : {
"type": "text",
"term_vector" : "with_positions_offsets"
}
}
}
}
}
--------------------------------------------------
// CONSOLE
[[plain-highlighter]]
==== Plain highlighter
This highlighter of type `plain` uses the standard Lucene highlighter.
It tries hard to reflect the query matching logic in terms of understanding word importance and any word positioning criteria in phrase queries.
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
2014-02-17 07:31:31 -05:00
[WARNING]
2017-06-09 08:09:57 -04:00
If you want to highlight a lot of fields in a lot of documents with complex queries this highlighter will not be fast.
In its efforts to accurately reflect query logic it creates a tiny in-memory index and re-runs the original query criteria through
Lucene's query execution planner to get access to low-level match information on the current document.
This is repeated for every field and every document that needs highlighting. If this presents a performance issue in your system consider using an alternative highlighter.
2014-02-17 07:31:31 -05:00
2014-06-22 10:46:33 -04:00
[[fast-vector-highlighter]]
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
==== Fast vector highlighter
2017-06-09 08:09:57 -04:00
This highlighter of type `fvh` uses the Lucene Fast Vector highlighter.
This highlighter can be used on fields with `term_vector` set to
`with_positions_offsets` in the mapping.
The fast vector highlighter:
2013-08-28 19:24:34 -04:00
* Is faster especially for large fields (> `1MB`)
2017-02-23 17:32:22 -05:00
* Can be customized with `boundary_scanner` (see <<boundary-scanners,below>>)
2013-10-18 12:03:31 -04:00
* Requires setting `term_vector` to `with_positions_offsets` which
2013-08-28 19:24:34 -04:00
increases the size of the index
2013-09-23 10:17:26 -04:00
* Can combine matches from multiple fields into one result. See
`matched_fields`
2013-12-05 12:56:39 -05:00
* Can assign different weights to matches at different positions allowing
for things like phrase matches being sorted above term matches when
highlighting a Boosting Query that boosts phrase matches over term matches
2013-08-28 19:24:34 -04:00
2016-10-06 23:46:55 -04:00
Here is an example of setting the `comment` field to allow for
2013-08-28 19:24:34 -04:00
highlighting using the fast vector highlighter on it (this will cause
the index to be bigger):
[source,js]
--------------------------------------------------
2017-04-05 17:38:34 -04:00
PUT /example
2013-08-28 19:24:34 -04:00
{
2017-04-05 17:38:34 -04:00
"mappings": {
"doc" : {
"properties": {
"comment" : {
"type": "text",
"term_vector" : "with_positions_offsets"
}
}
2013-08-28 19:24:34 -04:00
}
2017-04-05 17:38:34 -04:00
}
2013-08-28 19:24:34 -04:00
}
--------------------------------------------------
2017-04-05 17:38:34 -04:00
// CONSOLE
2016-05-18 09:52:08 -04:00
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
==== Force highlighter type
2017-06-09 08:09:57 -04:00
The `type` field allows to force a specific highlighter type.
The allowed values are: `unified`, `plain` and `fvh`.
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
The following is an example that forces the use of the plain highlighter:
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
"highlight" : {
"fields" : {
2016-10-06 23:46:55 -04:00
"comment" : {"type" : "plain"}
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
2013-12-09 05:57:59 -05:00
==== Force highlighting on source
Forces the highlighting to highlight fields based on the source even if fields are
stored separately. Defaults to `false`.
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-12-09 05:57:59 -05:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-12-09 05:57:59 -05:00
"highlight" : {
"fields" : {
2016-10-06 23:46:55 -04:00
"comment" : {"force_source" : true}
2013-12-09 05:57:59 -05:00
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-08-28 19:24:34 -04:00
2013-09-25 12:17:40 -04:00
[[tags]]
2013-08-28 19:24:34 -04:00
==== Highlighting Tags
By default, the highlighting will wrap highlighted text in `<em>` and
`</em>`. This can be controlled by setting `pre_tags` and `post_tags`,
for example:
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
"highlight" : {
"pre_tags" : ["<tag1>"],
"post_tags" : ["</tag1>"],
"fields" : {
"_all" : {}
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
Using the fast vector highlighter there can be more tags, and the "importance"
is ordered.
2013-08-28 19:24:34 -04:00
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-08-28 19:24:34 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-08-28 19:24:34 -04:00
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"_all" : {}
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-08-28 19:24:34 -04:00
There are also built in "tag" schemas, with currently a single schema
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
called `styled` with the following `pre_tags`:
2013-08-28 19:24:34 -04:00
2017-04-05 17:38:34 -04:00
[source,html]
2013-08-28 19:24:34 -04:00
--------------------------------------------------
<em class="hlt1">, <em class="hlt2">, <em class="hlt3">,
<em class="hlt4">, <em class="hlt5">, <em class="hlt6">,
<em class="hlt7">, <em class="hlt8">, <em class="hlt9">,
<em class="hlt10">
--------------------------------------------------
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
and `</em>` as `post_tags`. If you think of more nice to have built in tag
2013-08-28 19:24:34 -04:00
schemas, just send an email to the mailing list or open an issue. Here
is an example of switching tag schemas:
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-08-28 19:24:34 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-08-28 19:24:34 -04:00
"highlight" : {
"tags_schema" : "styled",
"fields" : {
2016-10-06 23:46:55 -04:00
"comment" : {}
2013-08-28 19:24:34 -04:00
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
==== Encoder
2013-08-28 19:24:34 -04:00
An `encoder` parameter can be used to define how highlighted text will
be encoded. It can be either `default` (no encoding) or `html` (will
escape html, if you use html highlighting tags).
==== Highlighted Fragments
Each field highlighted can control the size of the highlighted fragment
in characters (defaults to `100`), and the maximum number of fragments
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
to return (defaults to `5`).
For example:
2013-08-28 19:24:34 -04:00
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-08-28 19:24:34 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-08-28 19:24:34 -04:00
"highlight" : {
"fields" : {
2016-10-06 23:46:55 -04:00
"comment" : {"fragment_size" : 150, "number_of_fragments" : 3}
2013-08-28 19:24:34 -04:00
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-08-28 19:24:34 -04:00
Added third highlighter type based on lucene postings highlighter
Requires field index_options set to "offsets" in order to store positions and offsets in the postings list.
Considerably faster than the plain highlighter since it doesn't require to reanalyze the text to be highlighted: the larger the documents the better the performance gain should be.
Requires less disk space than term_vectors, needed for the fast_vector_highlighter.
Breaks the text into sentences and highlights them. Uses a BreakIterator to find sentences in the text. Plays really well with natural text, not quite the same if the text contains html markup for instance.
Treats the document as the whole corpus, and scores individual sentences as if they were documents in this corpus, using the BM25 algorithm.
Uses forked version of lucene postings highlighter to support:
- per value discrete highlighting for fields that have multiple values, needed when number_of_fragments=0 since we want to return a snippet per value
- manually passing in query terms to avoid calling extract terms multiple times, since we use a different highlighter instance per doc/field, but the query is always the same
The lucene postings highlighter api is quite different compared to the existing highlighters api, the main difference being that it allows to highlight multiple fields in multiple docs with a single call, ensuring sequential IO.
The way it is introduced in elasticsearch in this first round is a compromise trying not to change the current highlight api, which works per document, per field. The main disadvantage is that we lose the sequential IO, but we can always refactor the highlight api to work with multiple documents.
Supports pre_tag, post_tag, number_of_fragments (0 highlights the whole field), require_field_match, no_match_size, order by score and html encoding.
Closes #3704
2013-08-08 11:10:42 -04:00
On top of this it is possible to specify that highlighted fragments need
to be sorted by score:
2013-08-28 19:24:34 -04:00
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-08-28 19:24:34 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-08-28 19:24:34 -04:00
"highlight" : {
"order" : "score",
"fields" : {
2016-10-06 23:46:55 -04:00
"comment" : {"fragment_size" : 150, "number_of_fragments" : 3}
2013-08-28 19:24:34 -04:00
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-08-28 19:24:34 -04:00
2013-10-24 08:30:14 -04:00
If the `number_of_fragments` value is set to `0` then no fragments are
2013-10-18 12:03:31 -04:00
produced, instead the whole content of the field is returned, and of
course it is highlighted. This can be very handy if short texts (like
document title or address) need to be highlighted but no fragmentation
is required. Note that `fragment_size` is ignored in this case.
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-10-18 12:03:31 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-10-18 12:03:31 -04:00
"highlight" : {
"fields" : {
"_all" : {},
2016-10-06 23:46:55 -04:00
"blog.title" : {"number_of_fragments" : 0}
2013-10-18 12:03:31 -04:00
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-10-18 12:03:31 -04:00
2015-10-27 11:25:29 -04:00
When using `fvh` one can use `fragment_offset`
2013-10-18 12:03:31 -04:00
parameter to control the margin to start highlighting from.
2013-10-24 08:30:14 -04:00
In the case where there is no matching fragment to highlight, the default is
to not return anything. Instead, we can return a snippet of text from the
beginning of the field by setting `no_match_size` (default `0`) to the length
2017-03-17 13:10:13 -04:00
of the text that you want returned. The actual length may be shorter or longer than
2017-06-09 08:09:57 -04:00
specified as it tries to break on a word boundary.
2013-09-03 14:25:58 -04:00
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-09-03 14:25:58 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-09-03 14:25:58 -04:00
"highlight" : {
"fields" : {
2016-10-06 23:46:55 -04:00
"comment" : {
2013-09-03 14:25:58 -04:00
"fragment_size" : 150,
"number_of_fragments" : 3,
"no_match_size": 150
}
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-09-03 14:25:58 -04:00
2017-04-17 14:00:24 -04:00
==== Fragmenter
2017-06-09 08:09:57 -04:00
WARNING: This option is not supported by the `unified` highlighter
2017-04-17 14:00:24 -04:00
Fragmenter can control how text should be broken up in highlight snippets.
However, this option is applicable only for the Plain Highlighter.
There are two options:
[horizontal]
`simple`:: Breaks up text into same sized fragments.
`span`:: Same as the simple fragmenter, but tries not to break up text between highlighted terms (this is applicable when using phrase like queries). This is the default.
[source,js]
--------------------------------------------------
GET twitter/tweet/_search
{
"query" : {
"match_phrase": { "message": "number 1" }
},
"highlight" : {
"fields" : {
"message" : {
2017-06-09 08:09:57 -04:00
"type": "plain",
2017-04-17 14:00:24 -04:00
"fragment_size" : 15,
"number_of_fragments" : 3,
"fragmenter": "simple"
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:twitter]
Response:
[source,js]
--------------------------------------------------
{
...
"hits": {
"total": 1,
"max_score": 1.4818809,
"hits": [
{
"_index": "twitter",
"_type": "tweet",
"_id": "1",
"_score": 1.4818809,
"_source": {
"user": "test",
"message": "some message with the number 1",
"date": "2009-11-15T14:12:12",
"likes": 1
},
"highlight": {
"message": [
" with the <em>number</em>",
" <em>1</em>"
]
}
}
]
}
}
--------------------------------------------------
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,/]
[source,js]
--------------------------------------------------
GET twitter/tweet/_search
{
"query" : {
"match_phrase": { "message": "number 1" }
},
"highlight" : {
"fields" : {
"message" : {
2017-06-09 08:09:57 -04:00
"type": "plain",
2017-04-17 14:00:24 -04:00
"fragment_size" : 15,
"number_of_fragments" : 3,
"fragmenter": "span"
}
}
}
}
--------------------------------------------------
// CONSOLE
// TEST[setup:twitter]
Response:
[source,js]
--------------------------------------------------
{
...
"hits": {
"total": 1,
"max_score": 1.4818809,
"hits": [
{
"_index": "twitter",
"_type": "tweet",
"_id": "1",
"_score": 1.4818809,
"_source": {
"user": "test",
"message": "some message with the number 1",
"date": "2009-11-15T14:12:12",
"likes": 1
},
"highlight": {
"message": [
"some message with the <em>number</em> <em>1</em>"
]
}
}
]
}
}
--------------------------------------------------
// TESTRESPONSE[s/\.\.\./"took": $body.took,"timed_out": false,"_shards": $body._shards,/]
If the `number_of_fragments` option is set to `0`,
`NullFragmenter` is used which does not fragment the text at all.
This is useful for highlighting the entire content of a document or field.
2013-09-03 14:25:58 -04:00
2013-10-18 12:03:31 -04:00
==== Highlight query
2013-09-05 12:39:01 -04:00
It is also possible to highlight against a query other than the search
query by setting `highlight_query`. This is especially useful if you
use a rescore query because those are not taken into account by
highlighting by default. Elasticsearch does not validate that
`highlight_query` contains the search query in any way so it is possible
to define it so legitimate query results aren't highlighted at all.
Generally it is better to include the search query in the
`highlight_query`. Here is an example of including both the search
query and the rescore query in `highlight_query`.
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-09-05 12:39:01 -04:00
{
2016-06-21 05:27:27 -04:00
"stored_fields": [ "_id" ],
2013-09-05 12:39:01 -04:00
"query" : {
"match": {
2016-10-06 23:46:55 -04:00
"comment": {
2013-09-05 12:39:01 -04:00
"query": "foo bar"
}
}
},
"rescore": {
"window_size": 50,
"query": {
"rescore_query" : {
"match_phrase": {
2016-10-06 23:46:55 -04:00
"comment": {
2013-09-05 12:39:01 -04:00
"query": "foo bar",
2016-08-02 17:35:31 -04:00
"slop": 1
2013-09-05 12:39:01 -04:00
}
}
},
"rescore_query_weight" : 10
}
},
"highlight" : {
"order" : "score",
"fields" : {
2016-10-06 23:46:55 -04:00
"comment" : {
2013-09-05 12:39:01 -04:00
"fragment_size" : 150,
"number_of_fragments" : 3,
"highlight_query": {
"bool": {
"must": {
"match": {
2016-10-06 23:46:55 -04:00
"comment": {
2013-09-05 12:39:01 -04:00
"query": "foo bar"
}
}
},
"should": {
"match_phrase": {
2016-10-06 23:46:55 -04:00
"comment": {
2013-09-05 12:39:01 -04:00
"query": "foo bar",
2016-08-02 17:35:31 -04:00
"slop": 1,
2013-09-05 12:39:01 -04:00
"boost": 10.0
}
}
},
"minimum_should_match": 0
}
}
}
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-09-05 12:39:01 -04:00
2013-09-30 17:32:00 -04:00
[[highlighting-settings]]
2013-08-28 19:24:34 -04:00
==== Global Settings
Highlighting settings can be set on a global level and then overridden
at the field level.
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-08-28 19:24:34 -04:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2013-08-28 19:24:34 -04:00
"highlight" : {
"number_of_fragments" : 3,
"fragment_size" : 150,
"fields" : {
"_all" : { "pre_tags" : ["<em>"], "post_tags" : ["</em>"] },
2016-10-06 23:46:55 -04:00
"blog.title" : { "number_of_fragments" : 0 },
"blog.author" : { "number_of_fragments" : 0 },
"blog.comment" : { "number_of_fragments" : 5, "order" : "score" }
2013-08-28 19:24:34 -04:00
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-08-28 19:24:34 -04:00
2013-09-25 12:17:40 -04:00
[[field-match]]
2013-08-28 19:24:34 -04:00
==== Require Field Match
2015-05-08 14:12:55 -04:00
`require_field_match` can be set to `false` which will cause any field to
be highlighted regardless of whether the query matched specifically on them.
The default behaviour is `true`, meaning that only fields that hold a query
match will be highlighted.
2013-08-28 19:24:34 -04:00
2016-02-28 15:32:51 -05:00
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2016-02-28 15:32:51 -05:00
{
2016-05-17 15:00:15 -04:00
"query" : {
2016-05-18 09:52:08 -04:00
"match": { "user": "kimchy" }
2016-05-17 15:00:15 -04:00
},
2016-02-28 15:32:51 -05:00
"highlight" : {
2016-05-17 15:00:15 -04:00
"require_field_match": false,
"fields": {
"_all" : { "pre_tags" : ["<em>"], "post_tags" : ["</em>"] }
}
2016-02-28 15:32:51 -05:00
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2016-02-28 15:32:51 -05:00
2017-02-23 17:32:22 -05:00
[[boundary-scanners]]
==== Boundary Scanners
2013-08-28 19:24:34 -04:00
2017-03-17 13:10:13 -04:00
When highlighting a field using the unified highlighter or the fast vector highlighter,
you can specify how to break the highlighted fragments using `boundary_scanner`, which accepts
2017-02-23 17:32:22 -05:00
the following values:
2013-08-28 19:24:34 -04:00
2017-03-17 13:10:13 -04:00
* `chars` (default mode for the FVH): allows to configure which characters (`boundary_chars`)
2017-02-23 17:32:22 -05:00
constitute a boundary for highlighting. It's a single string with each boundary
character defined in it (defaults to `.,!? \t\n`). It also allows configuring
the `boundary_max_scan` to control how far to look for boundary characters
2017-03-17 13:10:13 -04:00
(defaults to `20`). Works only with the Fast Vector Highlighter.
2013-09-23 10:17:26 -04:00
2017-03-17 13:10:13 -04:00
* `sentence` and `word`: use Java's https://docs.oracle.com/javase/8/docs/api/java/text/BreakIterator.html[BreakIterator]
to break the highlighted fragments at the next _sentence_ or _word_ boundary.
2017-02-23 17:32:22 -05:00
You can further specify `boundary_scanner_locale` to control which Locale is used
to search the text for these boundaries.
2013-09-23 10:17:26 -04:00
2017-03-17 13:10:13 -04:00
[NOTE]
When used with the `unified` highlighter, the `sentence` scanner splits sentence
bigger than `fragment_size` at the first word boundary next to `fragment_size`.
You can set `fragment_size` to 0 to never split any sentence.
2013-09-23 10:17:26 -04:00
[[matched-fields]]
==== Matched Fields
2017-06-09 08:09:57 -04:00
WARNING: This is only supported by the `fvh` highlighter
2013-09-23 10:17:26 -04:00
The Fast Vector Highlighter can combine matches on multiple fields to
highlight a single field using `matched_fields`. This is most
intuitive for multifields that analyze the same string in different
ways. All `matched_fields` must have `term_vector` set to
`with_positions_offsets` but only the field to which the matches are
combined is loaded so only that field would benefit from having
`store` set to `yes`.
2016-10-06 23:46:55 -04:00
In the following examples `comment` is analyzed by the `english`
analyzer and `comment.plain` is analyzed by the `standard` analyzer.
2013-09-23 10:17:26 -04:00
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-09-23 10:17:26 -04:00
{
"query": {
"query_string": {
2016-10-06 23:46:55 -04:00
"query": "comment.plain:running scissors",
"fields": ["comment"]
2013-09-23 10:17:26 -04:00
}
},
"highlight": {
"order": "score",
"fields": {
2016-10-06 23:46:55 -04:00
"comment": {
"matched_fields": ["comment", "comment.plain"],
2013-09-23 10:17:26 -04:00
"type" : "fvh"
}
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-09-23 10:17:26 -04:00
The above matches both "run with scissors" and "running with scissors"
and would highlight "running" and "scissors" but not "run". If both
phrases appear in a large document then "running with scissors" is
sorted above "run with scissors" in the fragments list because there
are more matches in that fragment.
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-09-23 10:17:26 -04:00
{
"query": {
"query_string": {
"query": "running scissors",
2016-10-06 23:46:55 -04:00
"fields": ["comment", "comment.plain^10"]
2013-09-23 10:17:26 -04:00
}
},
"highlight": {
"order": "score",
"fields": {
2016-10-06 23:46:55 -04:00
"comment": {
"matched_fields": ["comment", "comment.plain"],
2013-09-23 10:17:26 -04:00
"type" : "fvh"
}
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2013-09-23 10:17:26 -04:00
The above highlights "run" as well as "running" and "scissors" but
still sorts "running with scissors" above "run with scissors" because
the plain match ("running") is boosted.
[source,js]
--------------------------------------------------
2016-05-17 15:00:15 -04:00
GET /_search
2013-09-23 10:17:26 -04:00
{
"query": {
"query_string": {
"query": "running scissors",
2016-10-06 23:46:55 -04:00
"fields": ["comment", "comment.plain^10"]
2013-09-23 10:17:26 -04:00
}
},
"highlight": {
"order": "score",
"fields": {
2016-10-06 23:46:55 -04:00
"comment": {
"matched_fields": ["comment.plain"],
2013-09-23 10:17:26 -04:00
"type" : "fvh"
}
}
}
}
--------------------------------------------------
2016-05-17 15:00:15 -04:00
// CONSOLE
2017-04-05 17:38:34 -04:00
// TEST[setup:twitter]
2016-05-17 15:00:15 -04:00
2013-09-23 10:17:26 -04:00
The above query wouldn't highlight "run" or "scissor" but shows that
it is just fine not to list the field to which the matches are combined
2016-10-06 23:46:55 -04:00
(`comment`) in the matched fields.
2013-09-23 10:17:26 -04:00
[NOTE]
Technically it is also fine to add fields to `matched_fields` that
don't share the same underlying string as the field to which the matches
are combined. The results might not make much sense and if one of the
2014-03-28 12:09:56 -04:00
matches is off the end of the text then the whole query will fail.
2013-09-23 10:17:26 -04:00
[NOTE]
===================================================================
There is a small amount of overhead involved with setting
`matched_fields` to a non-empty array so always prefer
[source,js]
--------------------------------------------------
"highlight": {
"fields": {
2016-10-06 23:46:55 -04:00
"comment": {}
2013-09-23 10:17:26 -04:00
}
}
--------------------------------------------------
2017-04-05 17:38:34 -04:00
// NOTCONSOLE
2013-09-23 10:17:26 -04:00
to
[source,js]
--------------------------------------------------
"highlight": {
"fields": {
2016-10-06 23:46:55 -04:00
"comment": {
"matched_fields": ["comment"],
2013-09-23 10:17:26 -04:00
"type" : "fvh"
}
}
}
--------------------------------------------------
2017-04-05 17:38:34 -04:00
// NOTCONSOLE
2013-09-23 10:17:26 -04:00
===================================================================
2014-01-07 13:37:25 -05:00
2014-01-08 18:37:18 -05:00
[[phrase-limit]]
2014-01-07 13:37:25 -05:00
==== Phrase Limit
2017-06-09 08:09:57 -04:00
WARNING: this is only supported by the `fvh` highlighter
2015-10-27 11:25:29 -04:00
The fast vector highlighter has a `phrase_limit` parameter that prevents
2014-01-07 13:37:25 -05:00
it from analyzing too many phrases and eating tons of memory. It defaults
to 256 so only the first 256 matching phrases in the document scored
considered. You can raise the limit with the `phrase_limit` parameter but
keep in mind that scoring more phrases consumes more time and memory.
If using `matched_fields` keep in mind that `phrase_limit` phrases per
matched field are considered.
2014-05-14 15:20:59 -04:00
2015-06-26 11:36:48 -04:00
[float]
2014-05-14 15:20:59 -04:00
[[explicit-field-order]]
=== Field Highlight Order
Elasticsearch highlights the fields in the order that they are sent. Per the
json spec objects are unordered but if you need to be explicit about the order
that fields are highlighted then you can use an array for `fields` like this:
[source,js]
--------------------------------------------------
2017-04-05 17:38:34 -04:00
GET /_search
{
2014-05-14 15:20:59 -04:00
"highlight": {
"fields": [
2017-04-05 17:38:34 -04:00
{ "title": {} },
{ "text": {} }
2014-05-14 15:20:59 -04:00
]
}
2017-04-05 17:38:34 -04:00
}
2014-05-14 15:20:59 -04:00
--------------------------------------------------
2017-04-05 17:38:34 -04:00
// CONSOLE
// TEST[setup:twitter]
2014-05-14 15:20:59 -04:00
None of the highlighters built into Elasticsearch care about the order that the
fields are highlighted but a plugin may.