2015-08-06 11:24:29 -04:00
|
|
|
[[term-vector]]
|
|
|
|
=== `term_vector`
|
|
|
|
|
|
|
|
Term vectors contain information about the terms produced by the
|
|
|
|
<<analysis,analysis>> process, including:
|
|
|
|
|
|
|
|
* a list of terms.
|
|
|
|
* the position (or order) of each term.
|
|
|
|
* the start and end character offsets mapping the term to its
|
|
|
|
origin in the original string.
|
2019-07-16 16:22:11 -04:00
|
|
|
* payloads (if they are available) — user-defined binary data
|
|
|
|
associated with each term position.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
These term vectors can be stored so that they can be retrieved for a
|
|
|
|
particular document.
|
|
|
|
|
|
|
|
The `term_vector` setting accepts:
|
|
|
|
|
|
|
|
[horizontal]
|
|
|
|
`no`:: No term vectors are stored. (default)
|
|
|
|
`yes`:: Just the terms in the field are stored.
|
|
|
|
`with_positions`:: Terms and positions are stored.
|
|
|
|
`with_offsets`:: Terms and character offsets are stored.
|
|
|
|
`with_positions_offsets`:: Terms, positions, and character offsets are stored.
|
2019-07-16 16:22:11 -04:00
|
|
|
`with_positions_payloads`:: Terms, positions, and payloads are stored.
|
|
|
|
`with_positions_offsets_payloads`:: Terms, positions, offsets and payloads are stored.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
2019-07-16 16:22:11 -04:00
|
|
|
The fast vector highlighter requires `with_positions_offsets`.
|
|
|
|
<<docs-termvectors, The term vectors API>> can retrieve whatever is stored.
|
2015-08-06 11:24:29 -04:00
|
|
|
|
|
|
|
WARNING: Setting `with_positions_offsets` will double the size of a field's
|
|
|
|
index.
|
|
|
|
|
2019-09-06 11:31:13 -04:00
|
|
|
[source,console]
|
2015-08-06 11:24:29 -04:00
|
|
|
--------------------------------------------------
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"mappings": {
|
2019-01-22 09:13:52 -05:00
|
|
|
"properties": {
|
|
|
|
"text": {
|
|
|
|
"type": "text",
|
|
|
|
"term_vector": "with_positions_offsets"
|
2015-08-06 11:24:29 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
PUT my-index-000001/_doc/1
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"text": "Quick brown fox"
|
|
|
|
}
|
|
|
|
|
2020-07-27 15:58:26 -04:00
|
|
|
GET my-index-000001/_search
|
2015-08-06 11:24:29 -04:00
|
|
|
{
|
|
|
|
"query": {
|
|
|
|
"match": {
|
|
|
|
"text": "brown fox"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"highlight": {
|
|
|
|
"fields": {
|
|
|
|
"text": {} <1>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2019-09-06 11:31:13 -04:00
|
|
|
|
2015-08-06 11:24:29 -04:00
|
|
|
<1> The fast vector highlighter will be used by default for the `text` field
|
|
|
|
because term vectors are enabled.
|
|
|
|
|