zoukankan      html  css  js  c++  java
  • es修改数据类型

    es创建好了mapping后是不允许修改字段类型的,要是我们想修改字段类型怎么办呢,我们可以采用reindex的方法实现,就是创建一个新的mapping,里面的字段类型按照新的类型定义,然后使用reindex的方法把原来的数据拷贝到新的index下面。

    1.查看原来的mapping

    [esuser@localhost ~]$ curl -u elastic:elastic -H "Content-Type: application/json" -XGET "http://192.168.1.85:9200/db_customer/_mappings?pretty=true"
    {
      "db_customer" : {
        "mappings" : {
          "tb_test" : {
            "properties" : {
              "name" : {
                "type" : "text",
                "fields" : {
                  "keyword" : {
                    "type" : "keyword",
                    "ignore_above" : 256
                  }
                }
              }
            }
          }
        }
      }
    }
    

    可以看到tb_test的字段name为text类型,我想将其修改成keyword类型

    2.创建新的index和mapping

    创建一个新的index
    curl -u elastic:elastic -H 'Content-Type: application/json' -XPUT "http://192.168.1.85:9200/copy01_db_customer"
    
    创建一个mapping
    curl -u elastic:elastic -H 'Content-Type: application/json' -XPOST "http://192.168.1.85:9200/copy01_db_customer/tb_test/_mapping?pretty" -d ' 
    {
        "tb_test": {
                "properties": {
                    "name": {
                        "type": "keyword",
                        "store": "true"
                    }
                }
            }
      }
    '
    

    这里创建了一个新的index叫做opy01_db_customer,相应的tb_test mapping 字段name 为keyword类型

    3.数据同步

    
    curl -u elastic:elastic -X POST "192.168.1.85:9200/_reindex" -H 'Content-Type: application/json' -d'
    {
      "source": {
        "index": "db_customer"
      },
      "dest": {
        "index": "copy01_db_customer"
      }
    }'
    

    4.再次查看新index结构

    [esuser@localhost ~]$ curl -u elastic:elastic -H "Content-Type: application/json" -XGET "http://192.168.1.85:9200/copy01_db_customer/_mappings?pretty=true"
    {
      "copy01_db_customer" : {
        "mappings" : {
          "tb_test" : {
            "properties" : {
              "name" : {
                "type" : "keyword",
                "store" : true
              }
            }
          }
        }
      }
    }
    
  • 相关阅读:
    std::type_index(转)
    __sync_fetch_and_add系列(转)
    InterlockedIncrement函数详解(转)
    如何让服务端同时支持WebSocket和SSL加密的WebSocket(即同时支持ws和wss)?(转)
    Linux系统管理基础测试
    CentOS7.7源码包安装Cmake3.0
    Shell-三剑客(sed)
    问题-突然发现公司网站访问速度变的很慢很慢
    Linux基础命令之文件及目录管理
    Linux基础命令之进程管理
  • 原文地址:https://www.cnblogs.com/blogabc/p/12664274.html
Copyright © 2011-2022 走看看