term_vector

Term vectors contain information about the terms produced by the 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.
  • payloads (if they are available) — user-defined binary data associated with each term position.

These term vectors can be stored so that they can be retrieved for a particular document.

The term_vector setting accepts:

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.

with_positions_payloads

Terms, positions, and payloads are stored.

with_positions_offsets_payloads

Terms, positions, offsets and payloads are stored.

The fast vector highlighter requires with_positions_offsets. The term vectors API can retrieve whatever is stored.

Setting with_positions_offsets will double the size of a field’s index.

  1. PUT my-index-000001
  2. {
  3. "mappings": {
  4. "properties": {
  5. "text": {
  6. "type": "text",
  7. "term_vector": "with_positions_offsets"
  8. }
  9. }
  10. }
  11. }
  12. PUT my-index-000001/_doc/1
  13. {
  14. "text": "Quick brown fox"
  15. }
  16. GET my-index-000001/_search
  17. {
  18. "query": {
  19. "match": {
  20. "text": "brown fox"
  21. }
  22. },
  23. "highlight": {
  24. "fields": {
  25. "text": {}
  26. }
  27. }
  28. }

The fast vector highlighter will be used by default for the text field because term vectors are enabled.