近日,发现同步数据到es的时候,有个新建的索引动态适配了mapping,而往往这种会有字段类型不是我们想要的,比如我这就有个tid字段,此字段要在聚合操作中使用,而此时的tid被识别成text类型了,而text不支持聚合,所以要更改字段类型为long或者keyword,注意es 不支持直接更改类型,所以就按以下麻烦的方法处理了下,解决问题
1、创建工具人索引testnamenew并自定义其mapping
PUT testnamenew
{
"mappings": {
"properties": {
"cotent" : {
"type" : "keyword"
},
"tid" : {
"type" : "long"
}
}
},
"settings": {
"index":{
"number_of_shards":1,
"number_of_replicas":1
}
}
}
2、查询工具人索引的相关信息
#单独查询某个索引的设置
GET /testnamenew/_settings
#查询testnamenew索引的document的结构
GET /testnamenew/_mapping
3、 使用下面的语句(POST _reindex),把原索引testnameold的值复制到新索引testnamenew上。
POST _reindex
{
"source": {
"index": "testnameold"
},
"dest": {
"index": "testnamenew"
}
}
4、查询新索引数据是否复制正确
GET /testnamenew/_search
5、#删除原索引
DELETE testnameold
6、此步骤非常重要,删除原索引后,需要在新建同名的索引,即在新建testnameold索引,设置符合你要求的mapping
PUT testnameold
{
"mappings": {
"properties": {
"cotent" : {
"type" : "keyword"
},
"tid" : {
"type" : "long"
}
}
},
"settings": {
"index":{
"number_of_shards":1,
"number_of_replicas":1
}
}
}
7、然后在把testnamenew的数据复制到新建的testnameold中,即需要执行以下的操作
POST _reindex
{
"source": {
"index": "testnamenew"
},
"dest": {
"index": "testnameold"
}
}
坑注:如果删除原索引,不在重新建一下testnameold,而直接执行_reindex,那么原索引的mapping还是原来错误的,这个是我这边遇到的坑。。。
7、以上都没什么问题后,你可以查看下testnameold索引的信息,此时的mapping应该就是符合你要求的喽,然后就可以删除工具人索引testnamenew了文章来源:https://www.toymoban.com/news/detail-479625.html
仅此记录,完结撒花✿✿ヽ(°▽°)ノ✿文章来源地址https://www.toymoban.com/news/detail-479625.html
到了这里,关于kibana中ES修改某个字段类型问题的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!