ElasticSearch在原索引基础上添加字段和修改字段

2023-05-16

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

业务场景:

现在的系统设计不满足业务需求时就需要升级服务,为了满足业务需求有时需要对ES中 字段进行添加或修改操作,接下来我们查看为 mappings 添加字段的相关操作:

在讲解添加字段的es原生API之前,我看先来说下查看ElasticSearch中索引信息的相关API:

一、查看索引Setting配置信息

GET  http://xxx.xxx.xxx.xxx:9200/supplier_index/_settings
{
    "supplier_index": {
        "settings": {
            "index": {
                "refresh_interval": "1s",
                "number_of_shards": "2",
                "provided_name": "supplier_index",
                "creation_date": "1528175417715",
                "analysis": {
                    "filter": {
                        "pinyin_first_letter_and_full_pinyin_filter": {
                            "keep_joined_full_pinyin": "true",
                            "keep_none_chinese_in_first_letter": "true",
                            "lowercase": "true",
                            "keep_original": "false",
                            "keep_first_letter": "true",
                            "trim_whitespace": "true",
                            "type": "pinyin",
                            "keep_none_chinese": "false",
                            "limit_first_letter_length": "16",
                            "keep_full_pinyin": "false"
                        },
                        "autocomplete_filter": {
                            "type": "edge_ngram",
                            "min_gram": "1",
                            "max_gram": "15"
                        },
                        "full_pinyin_filter": {
                            "keep_joined_full_pinyin": "true",
                            "keep_none_chinese_in_first_letter": "true",
                            "lowercase": "true",
                            "keep_original": "true",
                            "keep_first_letter": "true",
                            "trim_whitespace": "true",
                            "type": "pinyin",
                            "keep_none_chinese": "false",
                            "limit_first_letter_length": "16",
                            "keep_full_pinyin": "false"
                        }
                    },
                    "analyzer": {
                        "chinese_analyzer": {
                            "filter": [
                                "lowercase",
                                "autocomplete_filter"
                            ],
                            "char_filter": [
                                "html_strip"
                            ],
                            "type": "custom",
                            "tokenizer": "keyword"
                        },
                        "full_prefix_analyzer": {
                            "filter": [
                                "lowercase",
                                "full_pinyin_filter",
                                "autocomplete_filter"
                            ],
                            "char_filter": [
                                "html_strip"
                            ],
                            "type": "custom",
                            "tokenizer": "keyword"
                        },
                        "pinyin_analyzer": {
                            "filter": [
                                "pinyin_first_letter_and_full_pinyin_filter",
                                "autocomplete_filter"
                            ],
                            "char_filter": [
                                "html_strip"
                            ],
                            "type": "custom",
                            "tokenizer": "keyword"
                        }
                    }
                },
                "number_of_replicas": "1",
                "uuid": "jGquRxITT1KuhIE-QoZbKw",
                "version": {
                    "created": "5050099"
                }
            }
        }
    }
}

 

二、查看索引相关mappings相关配置信息

GET  http://xxx.xxx.xxx.xxx:9200/supplier_index/_mapping

{
    "supplier_index": {
        "mappings": {
            "category_type": {
                "properties": {
                    "advanceCharge": {
                        "type": "long"
                    },
                    "beginMembers": {
                        "type": "long"
                    },
                    "beginMoney": {
                        "type": "long"
                    },
                    "categoryId": {
                        "type": "long"
                    },
                    "categoryJoinId": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "categoryJoinName": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "cityIds": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "clearRequirment": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "commMode": {
                        "type": "long"
                    },
                    "commRate": {
                        "type": "long"
                    },
                    "createTime": {
                        "type": "date",
                        "format": "MMM dd, yyyy hh:mm:ss aa||yyyy-MM-dd HH:mm:ss||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
                    },
                    "evaluateRate": {
                        "type": "long"
                    },
                    "id": {
                        "type": "long"
                    },
                    "invoiceTaxPoint": {
                        "type": "long"
                    },
                    "invoiceType": {
                        "type": "long"
                    },
                    "isDel": {
                        "type": "integer"
                    },
                    "isSpecial": {
                        "type": "long"
                    },
                    "isTest": {
                        "type": "long"
                    },
                    "orderNum": {
                        "type": "long"
                    },
                    "orderStatus": {
                        "type": "long"
                    },
                    "otherRequirment": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "platformMode": {
                        "type": "long"
                    },
                    "promiseIds": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "receiveCondition": {
                        "type": "long"
                    },
                    "suppilerType": {
                        "type": "long"
                    },
                    "supplierId": {
                        "type": "long"
                    },
                    "supplierName": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "updateTime": {
                        "type": "date",
                        "format": "MMM dd, yyyy hh:mm:ss aa||yyyy-MM-dd HH:mm:ss||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
                    },
                    "weight": {
                        "type": "long"
                    }
                }
            },
            "goods_type": {
                "properties": {
                    "attrIds": {
                        "type": "text"
                    },
                    "auditStatus": {
                        "type": "integer"
                    },
                    "auditorId": {
                        "type": "long"
                    },
                    "brandId": {
                        "type": "long"
                    },
                    "brandName": {
                        "type": "text"
                    },
                    "cateId": {
                        "type": "long"
                    },
                    "cateJoinId": {
                        "type": "text"
                    },
                    "cateJoinName": {
                        "type": "text"
                    },
                    "cateName": {
                        "type": "text"
                    },
                    "cityIds": {
                        "type": "text"
                    },
                    "createTime": {
                        "type": "date",
                        "format": "MMM dd, yyyy hh:mm:ss aa||yyyy-MM-dd HH:mm:ss||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
                    },
                    "goodsImage": {
                        "type": "text"
                    },
                    "goodsImageId": {
                        "type": "long"
                    },
                    "goodsName": {
                        "type": "text"
                    },
                    "goodsStorage": {
                        "type": "integer"
                    },
                    "id": {
                        "type": "long"
                    },
                    "isDel": {
                        "type": "integer"
                    },
                    "lineStatus": {
                        "type": "integer"
                    },
                    "marketPrice": {
                        "type": "integer"
                    },
                    "saleNum": {
                        "type": "integer"
                    },
                    "shopId": {
                        "type": "long"
                    },
                    "skuId": {
                        "type": "long"
                    },
                    "specOpen": {
                        "type": "integer"
                    },
                    "startTime": {
                        "type": "date",
                        "format": "MMM dd, yyyy hh:mm:ss aa||yyyy-MM-dd HH:mm:ss||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
                    },
                    "supplierId": {
                        "type": "long"
                    },
                    "supplierName": {
                        "type": "text"
                    },
                    "updateTime": {
                        "type": "date",
                        "format": "MMM dd, yyyy hh:mm:ss aa||yyyy-MM-dd HH:mm:ss||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
                    }
                }
            },
            "supplier_type": {
                "properties": {
                    "address": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "businessLevel": {
                        "type": "long"
                    },
                    "cashDeposit": {
                        "type": "long"
                    },
                    "categoryIds": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "chargeEmail": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "chargeName": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "chargePhone": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "cityId": {
                        "type": "long"
                    },
                    "cityIds": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "companyProfile": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "countryId": {
                        "type": "long"
                    },
                    "createTime": {
                        "type": "date",
                        "format": "MMM dd, yyyy hh:mm:ss aa||yyyy-MM-dd HH:mm:ss||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
                    },
                    "establishYear": {
                        "type": "long"
                    },
                    "goodsNum": {
                        "type": "long"
                    },
                    "id": {
                        "type": "long"
                    },
                    "isDel": {
                        "type": "integer"
                    },
                    "isTest": {
                        "type": "long"
                    },
                    "isUsed": {
                        "type": "long"
                    },
                    "memberRange": {
                        "type": "long"
                    },
                    "orderStatus": {
                        "type": "long"
                    },
                    "orderSum": {
                        "type": "long"
                    },
                    "provinceId": {
                        "type": "long"
                    },
                    "serviceAdvantage": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "serviceCategoryIds": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "serviceDisadvantage": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "simpleName": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "status": {
                        "type": "long"
                    },
                    "supplierName": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "typicalCustomer": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    },
                    "updateTime": {
                        "type": "date",
                        "format": "MMM dd, yyyy hh:mm:ss aa||yyyy-MM-dd HH:mm:ss||yyyy/MM/dd HH:mm:ss||yyyy/MM/dd||epoch_millis"
                    },
                    "userAccount": {
                        "type": "text",
                        "fields": {
                            "keyword": {
                                "type": "keyword",
                                "ignore_above": 256
                            }
                        }
                    }
                }
            }
        }
    }
}

三、添加索引+类型的 字段

为索引self_index_v1的self_type类型添加字段

PUT http://172.16.11.119:9200/self_index_v1/_mapping/self_type
==>
{
	"self_type": {
		"properties":{
			"serviceAdvantage":{
				"type":  "text",
        		"index": "not_analyzed"
			}
		}
	}
}

不出以外的话ack提示添加成功

如果要修改一个字段呢,比如onSale字段类型为boolean,现在想要修改为string类型,去尝试一下:

curl -XPOST "http://127.0.0.1:9200/productindex/product/_mapping?pretty" -d '{
     "product": {
                "properties": {
                 "onSale":{
                    "type":"string" 
               }
            }
        }
}'

返回错误信息:

{
  "error" : {
    "root_cause" : [ {
      "type" : "illegal_argument_exception",
      "reason" : "mapper [onSale] of different type, current_type [boolean], merged_type [string]"
    } ],
    "type" : "illegal_argument_exception",
    "reason" : "mapper [onSale] of different type, current_type [boolean], merged_type [string]"
  },
  "status" : 400
}

ElasticSearch是不允许修改字段的type类型的,原因是一个字段的类型进行修改之后,ES会重新建立对这个字段的索引信息,ElasticsSearch的底层是Lucene库,字段类型修改至少需要设设计到分词方式,相关度,TF/IDF等倒排的生成 , 不允许修改在我看来应该是Lucene机制导致的。

 

不允许修改ElasticSearch索引这篇博文讲的很清楚,推荐一下:

Elasticsearch 的坑爹事——记录一次mapping field修改过程

 

 

 

转载于:https://my.oschina.net/LucasZhu/blog/1830471

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

ElasticSearch在原索引基础上添加字段和修改字段 的相关文章

随机推荐

  • linux好用的下载工具,四款linux下的好工具

    原标题 xff1a 四款linux下的好工具 linux下的好工具很多 xff0c 使用得当会极大的提高工作者的效率 下面小编为大家推荐四个比较好用并且实用的工具 xff0c 对这四款工具在centos和ubuntu两个系统下进行相应的安装
  • 用计算机怎么按e,在计算器上e的多少次方怎样按

    e的x次方计算器 自然常数e就是lim 1 43 1 x xlim 1 43 1 x x xff0c x 43 或lim 1 43 z 1 zlim 1 43 z 1 z xff0c z 0 xff0c 其值约为2 71828 xff0c
  • Docker容器

    官网 www docker com github https github com docker docker github io 开源的容器引擎 xff0c 可以让开发者打包应用以及依赖的库 xff0c 然后发布到任何流行的linux发行
  • 宝塔跨服务器传文件的命令,宝塔面板文件移动复制粘贴你所不知道的小技巧!...

    下面是编程之家 jb51 cc 通过网络收集整理的代码片段 编程之家小编现在分享给大家 xff0c 也给大家做个参考 使用宝塔面板的时候 xff0c 同名文件夹覆盖无法正确覆盖 xff0c 会提示指定目录已经存在的 例如不同的目录下都有一个
  • 云服务器如何显示不出来,云服务器安装显示不出来

    云服务器安装显示不出来 内容精选 换一换 GPU加速型云服务器 xff0c 需要安装Tesla驱动和CUDA工具包以实现计算加速功能 使用公共镜像创建的计算加速型 P系列 实例默认已安装特定版本的Tesla驱动 使用私有镜像创建的GPU加速
  • linux tcp 例程,tcpdump 常用例子

    tcpdump 是一个很常用的网络包分析工具 xff0c 可以用来显示通过网络传输到本系统的 TCP IP 以及其他网络的数据包 tcpdump 使用 libpcap 库来抓取网络报 xff0c 这个库在几乎在所有的 Linux Unix
  • 给你两个字符串str1,str2,找出str2在str1中的位置

    如题 题目参考链接 xff1a http blog csdn net hxz qlh article details 14110221 代码来自非原创 1 include lt iostream gt 2 include lt cstdio
  • Win10间歇性卡顿

    Win10间歇性卡顿 1 关闭不必要的服务 xff1a Windows Update Windows Search SuperFetch Background Intelligent Transfer Service 2 卸载电脑管家 xf
  • HTTP协议 (二) 基本认证

    http协议是无状态的 xff0c 浏览器和web服务器之间可以通过cookie来身份识别 桌面应用程序 比如新浪桌面客户端 xff0c skydrive客户端 跟Web服务器之间是如何身份识别呢 xff1f 阅读目录 什么是HTTP基本认
  • 字符串截取函数--C语言(转)

    1 include lt stdio h gt 2 include lt stdlib h gt 3 4 char substring char ch int pos int length 5 6 char pch 61 ch 7 定义一个
  • HTTP, WWW-Authenticate, Authorization 验证授权 | Apache验证 | Python处理

    2019独角兽企业重金招聘Python工程师标准 gt gt gt HTTP验证 有时你访问网页时会碰到这种情况 xff1a 这种方式是基于HTTP协议的一种验证方式 xff0c 这里可以参考HTTP协议的具体解释 xff1a http w
  • 虚拟化(KVM)

    虚拟化介绍 VMware Workstation就是虚拟化 虚拟化简单讲 xff0c 就是把一台物理计算机虚拟成多台逻辑计算机 xff0c 每个逻辑计算机里面可以运行不同的操作系统 xff0c 相互不受影响 xff0c 这样就可以充分利用硬
  • 头文件中的(全局)变量只能放声明,不能定义

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 头文件中的变量只能声明 xff0c 不能定义 xff0c 否则其他多个 c文件包含该头文件 xff0c 出现重复定义 xff0c 导致链接出错 ifndef define
  • 程序启动时的堆栈

    程序启动时 xff0c Linux把4种类型的信息存放到程序堆栈中 xff1a xff08 1 xff09 命令行参数 xff08 包括程序名称 xff09 的数目 xff08 2 xff09 从shell提示符执行的程序的名称 xff08
  • suse linux双网卡双网关配置

    公司有台SUSE LINUX服务器需要用到2个网络 xff0c 一个网段是192的 xff0c 用来上OP管理平台系统 一个是B网络 xff0c 网段是202的 xff0c 用来上外网 我们都知道一台电脑拥有两个网关是不可能的 xff0c
  • 统计学中抽样比例一般占百分之多少

    要具体问题具体分析 一般和要求的误差限 置信区间及总体方差有关系 比如最基本的简单随机抽样 其样本量确定公式就是1 n 61 1 N 43 d 2 u 2 S 2 样本量和误差限成反比 和置信区间及总体方差成正比 请问一堆url怎么算方差
  • emqtt 试用(二)验证 emq 和 mosquito 的共享订阅

    本地订阅 Local Subscription 本地订阅 Local Subscription 只在本节点创建订阅与路由表 xff0c 不会在集群节点间广播全局路由 xff0c 非常适合物联网数据采集应用 使用方式 订阅者在主题 Topic
  • spring security实现动态配置url权限的两种方法

    缘起 标准的RABC 权限需要支持动态配置 xff0c spring security默认是在代码里约定好权限 xff0c 真实的业务场景通常需要可以支持动态配置角色访问权限 xff0c 即在运行时去配置url对应的访问角色 基于sprin
  • 干货!2018年你值得一看的网页设计作品集赏析

    网页设计作品集 61 门面 43 能力 网页设计作品集对网页设计师而言 xff0c 既是网页门面 xff0c 也是个人专业素养的体现 那么在作品集设计上万不能掉以轻心 无论是制作一份简约大方还是极具表现力的精良作品集 xff0c 设计师们都
  • ElasticSearch在原索引基础上添加字段和修改字段

    2019独角兽企业重金招聘Python工程师标准 gt gt gt 业务场景 xff1a 现在的系统设计不满足业务需求时就需要升级服务 xff0c 为了满足业务需求有时需要对ES中 字段进行添加或修改操作 xff0c 接下来我们查看为 ma