Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
<img src="//i.stack.imgur.com/RUiNP.png" height="16" width="18" alt="" class="sponsor tag img">elasticsearch 在Elasticsearch中更改类型和重新索引_<img Src="//i.stack.imgur.com/RUiNP.png" Height="16" Width="18" Alt="" Class="sponsor Tag Img">elasticsearch_Logstash_Kibana_Elastic Stack_Reindex - Fatal编程技术网 elasticsearch 在Elasticsearch中更改类型和重新索引,elasticsearch,logstash,kibana,elastic-stack,reindex,elasticsearch,Logstash,Kibana,Elastic Stack,Reindex" /> elasticsearch 在Elasticsearch中更改类型和重新索引,elasticsearch,logstash,kibana,elastic-stack,reindex,elasticsearch,Logstash,Kibana,Elastic Stack,Reindex" />

elasticsearch 在Elasticsearch中更改类型和重新索引

elasticsearch 在Elasticsearch中更改类型和重新索引,elasticsearch,logstash,kibana,elastic-stack,reindex,elasticsearch,Logstash,Kibana,Elastic Stack,Reindex,我最近升级了我的麋鹿堆栈(使用redis 3.2.3、Elasticsearch 2.3.5和Kibana 4.5.4的logstash 2.3.4),从(使用redis 2.8.24的logstash 1.4.1/1.4.2、Elasticsearch 1.2.2和Kibana 3.1.1)升级。升级进行得很顺利,但升级后我有一些字段的类型冲突。此特定字段由logstash动态创建,因此Elasticsearch中没有整体映射。我花了相当多的时间研究如何改变这一点。每一篇在线文章都说我不能简单

我最近升级了我的麋鹿堆栈(使用redis 3.2.3、Elasticsearch 2.3.5和Kibana 4.5.4的logstash 2.3.4),从(使用redis 2.8.24的logstash 1.4.1/1.4.2、Elasticsearch 1.2.2和Kibana 3.1.1)升级。升级进行得很顺利,但升级后我有一些字段的类型冲突。此特定字段由logstash动态创建,因此Elasticsearch中没有整体映射。我花了相当多的时间研究如何改变这一点。每一篇在线文章都说我不能简单地更改现有数据的字段类型。许多文章提到我需要重新编制索引,但未能解释如何进行。下面是我更改类型和重新索引的确切步骤

从需要更改字段类型的当前索引获取映射:

curl -XGET http://localhost:9200/logstash-2016.05.30/_mapping?pretty=1 > logstash-2016.05.30
编辑logstash-2016.05.30文件,删除文件中的第二行(索引名)和最后第二行(花括号)。否则将不会更新映射。我想如果您将索引名编辑为新名称,它会起作用,但我没有尝试(我想应该尝试)

编辑logstash-2016.05.30文件,并更改类型(即长到字符串或字符串到长)。您可以使用类似字段使用的精确定义

"http_status" : {
  "type" : "string",
  "norms" : {
    "enabled" : false
  },
  "fields" : {
    "raw" : {
      "type" : "string",
      "index" : "not_analyzed",
      "ignore_above" : 256
    }
  }
},
改为:

"http_status" : {
  "type" : "long"
},
接下来创建新索引(追加新的或任何您想要的)

再次检查映射是否正确创建

curl -XGET http://localhost:9200/logstash-2016.05.30_new/?pretty
使用以下方法重新编制索引:

curl -XPOST  http://localhost:9200/_reindex -d '{
"source": {
"index" : "logstash-2016.05.30"
},
"dest" : {
"index" : "logstash-2016.05.30_new"
}
}'
对两个索引中的条目进行计数(应相同)

一旦满足要求,重新索引将成功删除旧索引

curl -XDELETE http://localhost:9200/logstash-2016.05.30
创建别名,以便仍可使用旧索引名

curl -XPOST  http://localhost:9200/_aliases -d '{
"actions": [
{ "add": {
"alias": "logstash-2016.05.30",
"index": "logstash-2016.05.30_new"
}}
]
}'
最后,导航到Kibana并选择设置和索引模式。单击重新加载图标以刷新字段列表。应消除所有冲突


请注意,这不是一个真正的问题,除非您觉得可以用另一种方式来完成,或者这是一个问题。

对于Elasticsearch 6,需要进行一些小的更改。否则,请严格遵循所有说明

要获得映射,请使用
pretty=true
而不是
pretty=1

curl -XGET http://localhost:9200/logstash-2016.05.30/_mapping?pretty=true > logstash-2016.05.30
对于所有XPUT/XPOST请求,现在必须将内容类型设置为application/json

curl -XPUT  http://localhost:9200/logstash-2016.05.30_new \
  -H 'Content-Type: application/json' -d @logstash-2016.05.30
curl -XGET http://localhost:9200/logstash-2016.05.30/_mapping?pretty=true > logstash-2016.05.30
curl -XPUT  http://localhost:9200/logstash-2016.05.30_new \
  -H 'Content-Type: application/json' -d @logstash-2016.05.30