使用现有列值更新Elastic Search的所有文档

时间:2017-01-26 06:07:05

标签: elasticsearch

我有一个字段" published_date"在弹性搜索中我有完整的日期,如 yyyy-MM-dd' H&H:mm:ss

我想为日期再创建3个列,其中我必须使用现有的 published_date 更新新的3列。

在e.s.中有没有内置的api来做这种工作?我正在使用elasticsearch 5。

1 个答案:

答案 0 :(得分:0)

您可以使用update-by-query API执行此操作。它可以归结为运行这样的东西:

POST your_index/_update_by_query
{
  "script": {
    "inline": "ctx._source.year = ctx._source.published_date.date.getYear(); ctx._source.month = ctx._source.published_date.date.getMonthOfYear(); ctx._source.day = ctx._source.published_date.date.getDayOfYear(); ",
    "lang": "groovy"
  },
  "query": {
    "match_all": {}
  }
}

另请注意,您需要enable dynamic scripting才能实现此目的。

相关问题