首页 > 其他分享 >Elasticsearch 修改字段类型

Elasticsearch 修改字段类型

时间:2023-06-09 09:59:24浏览次数:34  
标签:lowercase normalizer keyword 索引 track 修改 Elasticsearch 类型 type

由于ES不能像关系型数据库直接修改类型,所以要借助中间索引来完成

1、创建中间索引(字段维护正确的)

put: https://localhost/track_bak
{
    "settings": {
        "index": {
            "number_of_shards": "3",
            "number_of_replicas": "1",
            "max_result_window": "10000000"
        },
        "analysis": {
            "analyzer": {
                "sanalyzer": {
                    "tokenizer": "standard"
                }
            },
            "normalizer": {
                "lowercase": {
                    "type": "custom",
                    "filter": [
                        "lowercase"
                    ]
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "Id": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "TrackingNumber": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "ForwarderByID": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "OrderId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "OrderTypeId": {
                "type": "short"
            },
            "OrderTypeStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "PackageId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "WarehouseId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "PlatformId": {
                "type": "keyword"
            },
            "PlatformStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "AccountId": {
                "type": "short"
            },
            "AccountStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "InputUserId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "InputUserStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "StoreManagerId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "StoreManagerStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "CountryId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "CountryStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "UploadState": {
                "type": "short"
            },
            "UploadStateStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LastEvent": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LastUpdateTime": {
                "type": "date"
            },
            "NoUpdateTime": {
                "type": "double"
            },
            "LogisticsState": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LogisticsStateStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LogisticId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LogisticWayId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "SendTime": {
                "type": "date"
            },
            "ItemReceived": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "ItemDispatched": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "DepartfromAirport": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "ArrivalfromAbroad": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "CustomsClearance": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "DestinationArrived": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "Remark": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "TrackCode": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "Createon": {
                "type": "date"
            },
            "LastUpdOn": {
                "type": "date"
            },
            "DepartureNO": {
                "type": "keyword",
                "normalizer": "lowercase"
            }
        }
    }
}

2、重建索引(把老索引同步到备份索引)

post: https://localhost/_reindex
{
    "source": {
        "index": "track"
    },
    "dest": {
        "index": "track_bak"
    }
}

3、删掉有问题的老索引

DELETE track

4、创建同名老索引(也可以将新索引重命名为老索引,实践中遇到问题所以采用重建方式)

重命名方式(实践中碰到异常没来得及展开研究)
put: https://localhost/_aliases
{
  "actions": [
    {
      "add": {
        "index": "track_bak",
        "alias": "track"
      }
    }
  ]
}

采取重新创建方式
put: https://localhost/track
{
    "settings": {
        "index": {
            "number_of_shards": "3",
            "number_of_replicas": "1",
            "max_result_window": "10000000"
        },
        "analysis": {
            "analyzer": {
                "sanalyzer": {
                    "tokenizer": "standard"
                }
            },
            "normalizer": {
                "lowercase": {
                    "type": "custom",
                    "filter": [
                        "lowercase"
                    ]
                }
            }
        }
    },
    "mappings": {
        "properties": {
            "Id": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "TrackingNumber": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "ForwarderByID": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "OrderId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "OrderTypeId": {
                "type": "short"
            },
            "OrderTypeStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "PackageId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "WarehouseId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "PlatformId": {
                "type": "keyword"
            },
            "PlatformStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "AccountId": {
                "type": "short"
            },
            "AccountStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "InputUserId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "InputUserStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "StoreManagerId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "StoreManagerStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "CountryId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "CountryStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "UploadState": {
                "type": "short"
            },
            "UploadStateStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LastEvent": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LastUpdateTime": {
                "type": "date"
            },
            "NoUpdateTime": {
                "type": "double"
            },
            "LogisticsState": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LogisticsStateStr": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LogisticId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "LogisticWayId": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "SendTime": {
                "type": "date"
            },
            "ItemReceived": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "ItemDispatched": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "DepartfromAirport": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "ArrivalfromAbroad": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "CustomsClearance": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "DestinationArrived": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "Remark": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "TrackCode": {
                "type": "keyword",
                "normalizer": "lowercase"
            },
            "Createon": {
                "type": "date"
            },
            "LastUpdOn": {
                "type": "date"
            },
            "DepartureNO": {
                "type": "keyword",
                "normalizer": "lowercase"
            }
        }
    }
}

5、重建索引(把要备份索引同步到新索引)

post: https://localhost/_reindex
{
    "source": {
        "index": "track_bak"
    },
    "dest": {
        "index": "track"
    }
}

6、确认数据已全部同步之后,删除备份索引

DELETE track_bak

标签:lowercase,normalizer,keyword,索引,track,修改,Elasticsearch,类型,type
From: https://www.cnblogs.com/BOSET/p/17468299.html

相关文章

  • CentOS7 修改root的开机登陆密码+忘记root密码如何修改root密码
    一、修改root的开机登陆密码[root@TS004~]# passwd  //*更改当前的root用户密码命令ChangingpasswordforuserrootNewpassword:    //*(输入新密码,密输入的密码不会显示)Retypenewpassword:     //*(确认输入新密码,密输入的密码不会显示)passwd:allauthe......
  • atomic_enum rust 原子枚举类型
    https://docs.rs/atomic_enum/latest/atomic_enum/#[atomic_enum]#[derive(PartialEq)]enumCatState{Dead=0,BothDeadAndAlive,Alive,}letstate=AtomicCatState::new(CatState::Dead);state.store(CatState::Alive,Ordering::Relaxed);assert......
  • es索引数据复制并增加条件和修改目标数据值
    es操作同一个索引里数据的复制语法复制数据: POST_reindex{"source":{"index":"source_index"},"dest":{"index":"destination_index"}} 字段值修改:POSTsource_index/_update_by_query{&quo......
  • Linux 通过修改 grub 文件禁用节能模式
    1、执行vi/etc/default/grub命令以编辑该文件 将光标移至GRUB_CMDLINE_LINUX行,在rhgb前新增intel_idle.max_cstate=0intel_pstate=disable字段,输入wq命令,按回车即能保存退出。2、生成启动文件 3、将改动写入镜像 最后执行reboot或者shutdown-rnow命令来......
  • Java数据类型、数组
    Java数据类型基本数据类型(8种)byte\short\int\long\;float\double;char\boolean引用数据类型类、数组、接口、枚举、注解、记录一维数组packagecom.study.onearray;publicclassOneArrayTest01{//快捷方式:psvm+回车,快速生成main方法......
  • 实体类中嵌套Enum类型并想转换成JSON字符串时遇到的问题。
    实体类中嵌套Enum类型并想转换成JSON字符串时遇到的问题。先说明问题的产生,在自己写着玩的时候,新建了一个User类如下:packagecom.ma.xdo;importlombok.*;importjava.io.Serializable;/***@ClassNameUser*@DescriptionTODO*@Author@O_o*@Date2023/6/814:......
  • linux下修改文件的拥有者和用户组
    一、使用chown命令更改文件拥有者在shell中,可以使用chown命令来改变文件所有者。chown命令是changeowner(改变拥有者)的缩写。需要要注意的是,用户必须是已经存在系统中的,也就是只能改变为在/etc/passwd这个文件中有记录的用户名称才可以。chown......
  • javaScript通用数据类型校验_2
    /*要求:一、电话号码由数字、"("、")"和"-"构成二、电话号码为3到8位三、如果电话号码中包含有区号,那么区号为三位或四位四、区号用"("、")"或"-"和其他部分隔开用途:检查输入的电话号码格式是否正确输入:strPhone:字符串返回:如果通过验证返回true,否......
  • Javascript动态修改select选项
    1、向Select里添加OptionJs代码1.//IEonly,FF不支持Add方法2.functionfnAddItem(text,value){3.varselTarget=document.getElementById("selID");4.selTarget.Add(newOption("text","value"));5.}6.......
  • SQLServer查看端口号和修改端口号
    sqlserver默认的端口号是14331、查看端口号程序中找到SQLServerManagementStudio,连接sqlserver数据库,新建查询,运行execsys.sp_readerrorlog0,1,'listening'; 2、修改端口号所有程序中找到SQLServer配置管理器SQLServer网络配置--MSSQLSERVER的协议,TCP/IP,双击找到T......