Elasticsearch:如何存储术语向量

Nic*_*tto 7 elasticsearch morelikethis

我正在开发一个项目,我大量使用Elasticsearch并利用moreLikeThis查询来实现一些功能.MLT查询的官方文档说明如下:

为了加速分析,它可以帮助在索引时存储术语向量,但是以磁盘使用为代价.

在**如何工作*部分.现在的想法是调整映射,以便存储预先计算的术语向量.问题是文档中似乎不清楚应该如何做到这一点.一方面,在MLT文档中,它们提供了如下所示的示例映射:

curl -s -XPUT 'http://localhost:9200/imdb/' -d '{
  "mappings": {
    "movies": {
      "properties": {
        "title": {
          "type": "string",
          "term_vector": "yes"
         },
         "description": {
          "type": "string"
        },
        "tags": {
          "type": "string",
          "fields" : {
            "raw": {
              "type" : "string",
              "index" : "not_analyzed",
              "term_vector" : "yes"
            }
          }
        }
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

另一方面,在术语向量文档中,它们在示例1部分中提供了如下所示的映射

curl -s -XPUT 'http://localhost:9200/twitter/' -d '{
  "mappings": {
    "tweet": {
      "properties": {
        "text": {
          "type": "string",
          "term_vector": "with_positions_offsets_payloads",
          "store" : true,
          "index_analyzer" : "fulltext_analyzer"
         },
         "fullname": {
          "type": "string",
          "term_vector": "with_positions_offsets_payloads",
          "index_analyzer" : "fulltext_analyzer"
        }
      }
    }
    ....
Run Code Online (Sandbox Code Playgroud)

这应该 create an index that stores term vectors, payloads etc.

现在的问题是:应该使用哪个映射?这是文档中的缺陷还是我遗漏了什么?

kee*_*ety 9

你是对的,它似乎没有在当前版本的文档中明确提到,但是在即将发布的2.0版文档中有更详细的解释.

术语向量包含有关分析过程产生的术语的信息,包括:

  • 一系列术语.
  • 每个词的位置(或顺序).
  • 开始和结束字符偏移将术语映射到原始字符串中的原点.

可以存储这些术语向量,以便可以针对特定文档检索它们.

term_vector设置接受:

  • no:不存储术语向量.(默认)
  • yes:只存储字段中的条款
  • with_positions:存储条款和职位
  • with_offsets:存储术语和字符偏移
  • with_positions_offsets:存储术语,位置和字符偏移