es定制 dynamic mapping template(type)
  4Sc2EobNVfno 2023年11月20日 28 0

定制 dynamic mapping template(type)

PUT /my_index { "mappings": { "my_type": { "dynamic_templates": [ { "en": { "match": "*_en", "match_mapping_type": "string", "mapping": { "type": "text", "analyzer": "english" } } } ] } } } #使用了模板

PUT /my_index/my_type/3 { "title_en": "this is my dog"

} #没有使用模板

PUT /my_index/my_type/5 { "title": "this is my cat" }

GET my_index/my_type/_search { "query": { "match": { "title": "is" } } }

3.27重建索引

一个field的设置是不能修改的,如果要修改一个field,那么应该重新按照新的mapping,建立一个index,然后将数据批量查询出来,重新用bulk api写入到index中。

批量查询的时候,建议采用scroll api,并且采用多线程并发的方式来reindex数据,每次scroll就查询指定日期的一段数据,交给一个线程即可。

PUT /index1/type1/4 { "content":"1990-12-12" }

GET /index1/type1/_search

GET /index1/type1/_mapping

#报错 PUT /index1/type1/4 { "content":"I am very happy." }

#修改content的类型为string类型,报错,不允许修改

PUT /index1/_mapping/type1 { "properties": { "content":{ "type": "text" } } }

#创建一个新的索引,把index1索引中的数据查询出来导入到新的索引中 #但是应用程序使用的是之前的索引,为了不用重启应用程序,给index1这个索引起个#别名

PUT /index1/_alias/index2

#创建新的索引,把content的类型改为字符串

PUT /newindex { "mappings": { "type1":{ "properties": { "content":{ "type": "text" } } } } }

#使用scroll批量查询

GET /index1/type1/_search?scroll=1m { "query": { "match_all": {} }, "sort": ["_doc"], "size": 2 }

#使用bulk批量写入新的索引 POST /_bulk {"index":{"_index":"newindex","_type":"type1","_id":1}} {"content":"1982-12-12"}

#将别名index2和新的索引关联,应用程序不用重启

POST /_aliases { "actions": [ {"remove": {"index":"index1","alias":"index2"}}, {"add": {"index": "newindex","alias": "index2"}} ] }

GET index2/type1/_search

3.28 索引不可变的原因

倒排索引包括:

文档的列表,文档的数量,词条在每个文档中出现的次数,出现的位置,每个文档的长度,所有文档的平均长度

索引不变的原因:

不需要锁,提升了并发性能

可以一直保存在缓存中(filter)

节省cpu和io开销

【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月20日 0

暂无评论

推荐阅读
4Sc2EobNVfno
作者其他文章 更多