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

    环境:
    es版本:6.5.0

    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
              }
            }
          }
        }
      }
    }

    -- The End --

  • 相关阅读:
    linux系统判断内存是否达到瓶颈的小技巧
    利用tcpdump命令统计http的GET和POST请求
    tcpdump 基于mac地址抓取数据包
    使用liunx系统自带的工具sar监控指定接口速率
    Windows 环境搭建Redis集群
    Windows下RabbitMQ安装,部署,配置
    鼠标事件(二)
    鼠标事件(一)
    响应式web之媒体查询(一)
    UI事件之unload、resize和scroll
  • 原文地址:https://www.cnblogs.com/hxlasky/p/10175607.html
Copyright © 2011-2022 走看看