Elasticsearch 1.x添加时间戳的字段副本 [英] Elasticsearch 1.x add field copy of timestamp

查看:166
本文介绍了Elasticsearch 1.x添加时间戳的字段副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在ES 1.5.2工作。我有一个带有文档的索引,带有存储的时间戳值。我想给它添加一个常规字段,它将假定该文档的_timestamp字段的值。我该怎么做?我可以做

  PUT twitter / _mapping / new_timestamp 
{
properties:{
name:{
type:float
}
}
}

创建一个常规字段,但如何复制所有_timestamp值呢?

解决方案

在ES 1.5.2中,您可以使用按查询插件更新为了重新索引您的文档,并将 _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中启用了动态脚本启用的www.elastic.co/guide/en/elasticsearch/reference/1.5/modules-scripting.html#_enabling_dynamic_scriptingrel =nofollow noreferrer 配置文件,您将能够运行以下命令

  POST / twitter / _update_by_query 
{
script:{
inline:ctx._source.new_timestamp = ctx._timestamp
},
query:{
match_all:{}
}
}


I am working in ES 1.5.2. I have an index with documents, with stored timestamp values. I want to add a regular field to it, which will assume the value of the _timestamp field for that document. How can I do this? I could do

PUT twitter/_mapping/new_timestamp
{
  "properties": {
    "name": {
      "type": "float"
    }
  }
}

to create a regular field, but how can I copy over all the _timestamp values to it?

In ES 1.5.2, you can use the update by query plugin in order to reindex your documents and copy the _timestamp field to a regular field.

After installing the plugin with the following command:

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

And making sure that dynamic scripting is enabled in your elasticsearch.yml configuration file, you'll be able to run the following command

POST /twitter/_update_by_query
{
  "script": {
    "inline": "ctx._source.new_timestamp = ctx._timestamp"
  },
  "query": {
    "match_all": {}
  }
}

这篇关于Elasticsearch 1.x添加时间戳的字段副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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