Term_vectors(词根信息)

Term vectors 是通过分析器解析产生的信息,包括:

  • 一组 terms (词根)。
  • 每个词根的位置(顺序)。
  • 映射词根的首字符和尾字符与原始字符串原点的偏移量。

这些 term vectors 将被存储,一遍将他从一个特定的文档中取出。

term_vector 有一下参数设置:

| no | 不存储 term vectors 信息。(默认值) | | yes | 仅次字段中的 terms(词根)被存储。 | | with_positions | 存储词根和位置。 | | with_offset | 存储词根和字符偏移量。 | | with_positions_offsets | 存储词根、位置和字符偏移量。 |

fast vector highlighter 需要用到 with_positions_offsetsterm vectors API 可以检索存储的任何内容。

警告

使用 with_positions_offsets 将会是字段的索引大小增加一倍。

  1. curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
  2. {
  3. "mappings": {
  4. "my_type": {
  5. "properties": {
  6. "text": {
  7. "type": "text",
  8. "term_vector": "with_positions_offsets"
  9. }
  10. }
  11. }
  12. }
  13. }
  14. '
  15. curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
  16. {
  17. "text": "Quick brown fox"
  18. }
  19. '
  20. curl -XGET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d'
  21. {
  22. "query": {
  23. "match": {
  24. "text": "brown fox"
  25. }
  26. },
  27. "highlight": {
  28. "fields": {
  29. "text": {} #1
  30. }
  31. }
  32. }
  33. '

| 1 | 因为 term vectors 功能的使用,text 字段将会默认使用 fast vector highlighter。 |

原文链接 : https://www.elastic.co/guide/en/elasticsearch/reference/5.3/term-vector.html(修改该链接为官网对应的链接)

译文链接 : http://www.apache.wiki/pages/viewpage.action?pageId=10027731(修改该链接为 ApacheCN 对应的译文链接)

贡献者 : 郭峰ApacheCNApache中文网