Elasticsearch 增加字段,并设置默认值

Elasticsearch 增加字段,并设置默认值,第1张

1.添加字段

备注:

test_idx: 索引名称

test: 索引中 mappings 的下一级对象

bookNum: 需要添加的属性

obj1: 索引中的子对象

响应如下才能说明新增成功

2.给新增的字段增加默认值

背景:

Elasticsearch具有动态mapping的功能,如果没有设置字段的映射,Elasticsearch将会对字段进行动态映射。但是有时候动态映射会出现不符合业务需求的字段映射,比如时间戳的映射,elasticsearch将其自动映射为long类型,但是在业务使用中需要date类型。

更改索引blog中的动态映射字段priority数据类型:由long更改为date

一、新建动态索引模板,此时time字段为long类型

puthttp://localhost:9200/_template/test

2、存入样本数据

post http://localhost:9200/test_001/test

3、更改动态模板中time的字段类型为date,并新建索引模板,同步骤1

put http://localhost:9200/_template/test

4、将test_001数据reindex到test_001_new

post http://localhost:9200/_reindex

5、删除旧索引 test_001

delete http://localhost:9200/test_001

6、将test_001_new数据reindex到test_001

post http://localhost:9200/_reindex


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11292430.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-15
下一篇 2023-05-15

发表评论

登录后才能评论

评论列表(0条)

保存