ElasticSearch学习笔记 | Mapping映射的创建、修改和删除
发布日期:2021-07-28 08:29:48
浏览次数:2
分类:技术文章
本文共 2720 字,大约阅读时间需要 9 分钟。
本文测试数据为官方提供的测试数据,导入方法在学习笔记本章节第一篇中:https://blog.csdn.net/qq_20051535/article/details/113242821
一、查询映射
映射是定义文档及其包含的字段的存储和索引方式的过程。例如,使用映射定义:哪些字符串字段应视为全文字段。
哪些字段包含数字,日期或地理位置。 日期值 的格式。 自定义规则,用于控制动态添加字段的映射 。 查询bank的映射信息GET /bank/_mapping
返回结果:{
"bank" : { "mappings" : { "properties" : { "account_number" : { "type" : "long" }, "address" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", "ignore_above" : 256 } } }, "age" : { "type" : "long" }, "balance" : { "type" : "long" }, ... 二、新建映射 我们可以利用put方法指定映射关系。例如:
创建age为一个integer字段
创建email为一个keyword字段 创建name为一个text字段 PUT /my_index { "mappings": { "properties": { "age":{ "type": "integer" }, "email":{ "type": "keyword" }, "name":{ "type": "text" } } } } 返回内容{
"acknowledged" : true, "shards_acknowledged" : true, "index" : "my_index" } 三、添加新的字段映射 比如我们需要新增一个字段,名字是 employee-id该index选项控制是否对字段值建立索引。它接受true 或false,默认为true。未索引的字段不可查询
PUT /my_index/_mapping
{ "properties":{ "employee-id":{ "type": "keyword", "index": false } } } 返回结果:{
"acknowledged" : true } 四、更改映射 对于已经存在的映射字段,我们不能更新,更新必须创建新的索引进行数据迁移。我们先来创建新的映射关系,稍后我们将进行数据迁移
PUT /newbank
{ "mappings": { "properties": { "account_number" : { "type" : "long" }, "address" : { "type" : "text" }, "age" : { "type" : "integer" }, "balance" : { "type" : "long" }, "city" : { "type" : "keyword" }, "email" : { "type" : "keyword" }, "employer" : { "type" : "keyword" }, "firstname" : { "type" : "text" }, "gender" : { "type" : "keyword" }, "lastname" : { "type" : "text", "fields" : { "keyword" : { "type" : "keyword", "ignore_above" : 256 } } }, "state" : { "type" : "keyword" } } } } 五、数据迁移 先创建新的映射,然后使用如下的方式进行迁移新版本不包含Type属性的迁移方式:
POST _reindex
{ "source":{ "index": "twitter" }, "dest":{ "index": "new_twitter" } } 将旧索引的type下的数据进行迁移POST _reindex
{ "source": { "index": "bank", "type": "account" }, "dest": { "index": "newbank" } } 返回结果,显示迁移成功#! Deprecation: [types removal] Specifying types in reindex requests is deprecated.
{ "took" : 529, "timed_out" : false, "total" : 1000, "updated" : 0, "created" : 1000, "deleted" : 0, "batches" : 1, "version_conflicts" : 0, "noops" : 0, "retries" : { "bulk" : 0, "search" : 0 }, "throttled_millis" : 0, "requests_per_second" : -1.0, "throttled_until_millis" : 0, "failures" : [ ] } 再次查询确认迁移数据成功GET /newbank/_search
{ "took" : 8, "timed_out" : false, "_shards" : { "total" : 1, "successful" : 1, "skipped" : 0, "failed" : 0 }, "hits" : { "total" : { "value" : 1000, "relation" : "eq" }, "max_score" : 1.0, "hits" : [ { "_index" : "newbank", "_type" : "_doc", //type都变成了_doc,8.0将彻底取消type属性 "_id" : "1", "_score" : 1.0,————————————————
版权声明:本文为CSDN博主「北鹤M」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/qq_20051535/article/details/113250151转载地址:https://blog.csdn.net/sinat_17775997/article/details/116118504 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
很好
[***.229.124.182]2024年03月30日 13时28分19秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
【开发篇】10分钟快速上手spring boot
2019-04-26
【开发篇】10分钟快速spring boot+react前后端分离
2019-04-26
【Leetcode刷题篇】leetcode203 移除链表元素
2019-04-26
【Leetcode刷题篇】leetcode938 二叉搜索树的范围和
2019-04-26
【Java网络编程与IO流】Java中BIO、NIO、AIO的区别是什么?
2019-04-26
【Leetcode刷题篇】leetcode136 只出现一次的数字
2019-04-26
spring boot整合thymeleaf,支持JSP和HTML页面开发
2019-04-26
【Java网络编程与IO流】Spring boot整合SSE实现服务器实时推送流信息
2019-04-26
【Leetcode刷题篇】leetcode141 环形链表II
2019-04-26
【Leetcode刷题篇】leetcode160 相交链表
2019-04-26
【Leetcode刷题篇】leetcode169 多数元素
2019-04-26
【Leetcode刷题篇】leetcode461 汉明距离
2019-04-26
【Leetcode刷题篇】leetcode204 计数质数
2019-04-26
【Leetcode刷题篇】leetcode70 爬楼梯
2019-04-26
【Leetcode刷题篇】leetcode739 每日温度
2019-04-26
【Leetcode刷题篇】leetcode121买卖股票的最佳时机
2019-04-26
【面试篇】Java多线程并发-Java关键字volatile详解
2019-04-26
【面试篇】Java的代理模式-静态代理和动态代理详解
2019-04-26
【面试篇】 Java对象拷贝(对象克隆 对象复制)
2019-04-26