倒排索引与重建索引
序号 | 内容 | 链接地址 |
---|---|---|
1 | SpringBoot整合Elasticsearch7.6.1 | https://blog.csdn.net/miaomiao19971215/article/details/105106783 |
2 | Elasticsearch Filter执行原理 | https://blog.csdn.net/miaomiao19971215/article/details/105487446 |
3 | Elasticsearch 倒排索引与重建索引 | https://blog.csdn.net/miaomiao19971215/article/details/105487532 |
4 | Elasticsearch Document写入原理 | https://blog.csdn.net/miaomiao19971215/article/details/105487574 |
5 | Elasticsearch 相关度评分算法 | https://blog.csdn.net/miaomiao19971215/article/details/105487656 |
6 | Elasticsearch Doc values | https://blog.csdn.net/miaomiao19971215/article/details/105487676 |
7 | Elasticsearch 搜索技术深入 | https://blog.csdn.net/miaomiao19971215/article/details/105487711 |
8 | Elasticsearch 聚合搜索技术深入 | https://blog.csdn.net/miaomiao19971215/article/details/105487885 |
9 | Elasticsearch 内存使用 | https://blog.csdn.net/miaomiao19971215/article/details/105605379 |
10 | Elasticsearch ES-Document数据建模详解 | https://blog.csdn.net/miaomiao19971215/article/details/105720737 |
一. 倒排索引
1.1 倒排索引的结构
(1)包含这个关键词的document list
(2)包含这个关键词的所有document的数量:IDF(inverse document frequency)
(3)这个关键词在每个document中出现的次数:TF(term frequency)
(4)这个关键词在这个document中的次序
(5)每个document的长度:length norm
(6)包含这个关键词的所有document的平均长度
1.2 倒排索引不可变的好处
(1)不需要锁,提升并发能力,避免锁的问题
(2)数据不变,一直保存在os cache中,只要cache内存足够
(3)filter cache一直驻留在内存,因为数据不变,同一个过滤条件下得到的bitset一定不会变。
(4)可以压缩,节省cpu和io开销
二. 重建索引
没有哪一个架构师敢说自己设计的index完美无缺,经过一段时间的使用后,往往会根据实际的业务场景,对原有结构进行调整。但遗憾的是,ES不允许对已存在的字段进行修改和删除,比如不能修改字段的类型,字段的分词器,增加新的子字段等操作,原因是这样会倒排索引的结构发生变化。
重建索引的方法如下: 新建一个index,为其设置定制化的mapping,接着将旧数据从旧索引中迁移到新索引中。迁移数据的方法非常多,比如通过scroll滚动读取数据,接着通过bulk POST create操作,将数据批量新增至新索引。
但重建索引不可避免的带来一个问题: 需要重新创建一个新索引。如果程序中操作ES的代码在书写index时使用了硬编码,那么重建索引就会导致整个系统不可用,必须修改代码再重启系统才能恢复功能。为了避免重启系统,实现零停机,我们需要在程序中使用index的别名。