term_vectors(词根信息)

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

  • 一组terms(词根)。

  • 每个词根的位置(顺序)。

  • 映射词根的首字符和尾字符与原始字符串原点的偏移量。

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

term_vector 有一下参数设置:

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

警告

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

curl -XPUT 'localhost:9200/my_index?pretty' -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "my_type": {
      "properties": {
        "text": {
          "type":        "text",
          "term_vector": "with_positions_offsets"
        }
      }
    }
  }
}
'
curl -XPUT 'localhost:9200/my_index/my_type/1?pretty' -H 'Content-Type: application/json' -d'
{
  "text": "Quick brown fox"
}
'
curl -XGET 'localhost:9200/my_index/_search?pretty' -H 'Content-Type: application/json' -d'
{
  "query": {
    "match": {
      "text": "brown fox"
    }
  },
  "highlight": {
    "fields": {
      "text": {} #1
    }
  }
}
'

解析

如上所述,词属性可以取6值,它定义是否要计算该字段的Lucene词向量(term vector).如果使用高亮,那就需要计算这个词向量.

Last updated