弹性搜索用文档中字段 A 的值中的单词数组填充字段 B

Elastic search fill field B with array of words from the value of field A in document

我想添加一个字段 B,它应该包含一个包含字段 A 的单词的数组。我想使用某种脚本将字段 A 的值分解为单词的部分。

所以像这样: 字段 A:"The Quick Brown Fox" 字段 B:["The","Quick","Brown","Fox"]

我正在谷歌搜索如何在 ElasticSearch 5.6 中实现这一点

您可以使用 update by query API 和一个拆分字段 A 并将结果数组存储到字段 B 的脚本来实现此目的:

POST test/_update_by_query
{
  "script": {
    "inline": "ctx._source.fieldB = /\s+/.split(ctx._source.fieldA);",
    "lang": "painless"
  },
  "query": {
    "match_all": {}
  }
}

你会得到这个:

    {
      "fieldA" : "The brown fox",
      "fieldB" : [
        "The",
        "brown",
        "fox"
      ]
    }