热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

elasticsearch中修改mapping实战

参考:https:www.phpmianshi.com?id200查询原有mapping登录kibana的IndexManagement查看Mapping{m

参考:https://www.phpmianshi.com/?id=200

查询原有mapping

登录kibana的Index Management 查看 Mapping

{"mapping": {"properties": {"@timestamp": {"type": "date"},"@version": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"create_time": {"type": "long"},"discuss_num": {"type": "long"},"hot_num": {"type": "long"},"hot_time": {"type": "date"},"id": {"type": "long"},"is_hot": {"type": "long"},"title": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"topic_sort": {"type": "long"},"type": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"update_at": {"type": "date"}}}
}

 

设置新的index和mapping (比如修改l_id为text类型,keyword分词,注意修改 mapping为mappings)

注意:我们这里把is_top设置为text  keyword 因为看上去是数字,但是其实是精准查询

PUT topic_v1
{"mappings": {"properties": {"@timestamp": {"type": "date"},"@version": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"create_time": {"type": "long"},"discuss_num": {"type": "long"},"hot_num": {"type": "long"},"hot_time": {"type": "date"},"id": {"type": "long"},"is_hot": {"type": "text","fielddata": true,"fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"title": {"type": "text","analyzer":  "ik_max_word","search_analyzer":  "ik_max_word"},"topic_sort": {"type": "long"},"type": {"type": "text","fields": {"keyword": {"type": "keyword","ignore_above": 256}}},"update_at": {"type": "date"}}}
}

 

修改logstash同步配置文件,把mysql可能为空字符串的字段设置为 none

select id,title,is_hot,hot_time,topic_sort,hot_num
,discuss_num,unix_timestamp(created_at) as create_time,update_at,(CASE state WHEN '' THEN 'none' ELSE state END) as es_state from topic wher
e update_at >=:sql_last_value order by update_at asc,id asc

 

创建索引别名,下次需要重建索引的时候,直接把新的索引别名设置为topic_alias就可以不用动代码,平滑切换了

PUT /topic_v1/_alias/topic_alias

查看别名都指向哪些索引

GET /*/_alias/topic_alias

验证新的别名功能都正常后,可以平滑切换索引,删除旧索引的别名,添加新索引的别名

POST /_aliases 
{"actions": [{"remove": {"index": "topic_v1","alias": "topic_alias"}}, {"add": {"index": "topic_v2","alias": "topic_alias"}}]
}

 


推荐阅读
author-avatar
手机用户2502918767
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有