使用现有列值更新Elastic Search的所有文档 [英] Update all documents of Elastic Search using existing column value

查看:64
本文介绍了使用现有列值更新Elastic Search的所有文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在弹性搜索中有一个字段"published_date",并且我有完整的日期,例如 yyyy-MM-dd'T'HH:mm:ss .

I have a field "published_date" in elastic search and there I have full date like yyyy-MM-dd'T'HH:mm:ss.

我想为日期创建另外3列,这些列必须使用现有的 published_date 更新新的3列.

I want to create 3 more columns for year, month and date where I have to use the existing published_date to update new 3 columns.

在e.s.中是否有任何内置的api可以进行这种工作?我正在使用Elasticsearch 5.

Is there any inbuilt api to do this kind of work in e.s.? I am using elasticsearch 5.

推荐答案

您可以使用

You can use the update-by-query API in order to do this. It would simply boil down to running something like this:

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": {}
  }
}

还要注意,您需要

Also note that you need to enable dynamic scripting in order for this to work.

这篇关于使用现有列值更新Elastic Search的所有文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆