es 的字段类型到底该怎么替换

最近使用es的时候,在模糊查询的时候,该字段使用了分词字段类型,导致了分词字段类型又用了分词查询,导致的结果就是啥都没检索出来。
基于上边的情况做了更改,但是天算不如人算呀,自己的插入字段配置被改了字段类行,导致测试和生产字段不一致。
算了,不唠叨,开始。
因为字段类型不一致,网上搜索了很多方法,都是没有直接更改字段类型的命令,全是新建索引再去复制数据。泪奔啊。
基于kibana 操作
原索引 名称 me_sad_dev

使用GET me_sad_dev(索引名)/_mapping 查询出原索引数据结构

{
    "mappings": {
      "doc": {
        "properties": {
          "catalogueId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "catalogueTags": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "contentType": {
            "type": "long"
          },
          "createTime": {
            "type": "long"
          }, 
          "imageUrl": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
    
          "openStatus": {
            "type": "long"
          },
          "openType": {
            "type": "long"
          },
       
          "relatedWords": {
            "type": "keyword"
          }
        }
      }
    }
  
}

新建一个索引 me_sad_dev_copy
PUT me_sad_dev_copy

{
    "mappings": {
      "doc": {
        "properties": {
          "catalogueId": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "catalogueTags": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "contentType": {
            "type": "long"
          },
          "createTime": {
            "type": "long"
          }, 
          "imageUrl": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
    
          "openStatus": {
            "type": "long"
          },
          "openType": {
            "type": "long"
          },
       
          "relatedWords": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
      }
    }
}

注意新建索引更改你所需要的类型

/**
 原字段类型
*/
 "relatedWords": {
            "type": "keyword"
          }
/**
  *新字段类型
*/
 "relatedWords": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }

把老表数据复制到新表里

POST /_reindex
{
  "source": {
    "index": "me_sad_dev"
  },
  "dest": {
    "index": "me_sad_dev_copy"
  }
}

现在就是新索引的数据和字段类型都是你需要的
删除 老索引

DELETE me_sad_dev

可以把新索引名 别名 成 原索引名

POST /_aliases
  {
        "actions": [
            {"add": {"index": "me_sad_dev_copy", "alias": "me_sad_dev"}}
        ]
  }

还有另一种方法就是在新建一个和原索引一样的名,重复赋值,就是把一二三步再执行一次

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值