我在ES 1.5.2中工作。我有一个包含文档的索引,并带有存储的时间戳值。我想向其中添加一个常规字段,该字段将采用该文档的_timestamp字段的值。我怎样才能做到这一点?我可以
PUT twitter/_mapping/new_timestamp { "properties": { "name": { "type": "float" } } }
创建一个常规字段,但是如何将所有_timestamp值复制到该字段?
在ES 1.5.2中,可以使用按查询更新插件来重新索引文档并将该_timestamp字段复制到常规字段。
_timestamp
使用以下命令安装插件后:
bin/plugin -url http://oss.sonatype.org/content/repositories/releases/com/yakaz/elasticsearch/plugins/elasticsearch-action-updatebyquery/1.0.0/elasticsearch-action-updatebyquery-1.0.0.zip install elasticsearch-action-updatebyquery
并且确保在配置文件中启用了动态脚本编制elasticsearch.yml,您将能够运行以下命令
elasticsearch.yml
POST /twitter/_update_by_query { "script": { "inline": "ctx._source.new_timestamp = ctx._timestamp” }, "query": { "match_all": {} } }