Update all documents of Elastic Search using existing column value

主宰稳场 提交于 2021-01-29 03:10:30

问题


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

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.

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


回答1:


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.



来源:https://stackoverflow.com/questions/41867756/update-all-documents-of-elastic-search-using-existing-column-value

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!