#Elasticsearch# 文章列表 Elasticsearch 介绍 Elasticsearch 7:快速上手 Elasticsearch 7:关于 Index、Type、Document Elasticsearch 7:安装与启动 Elasticsearch 7:Kibana 的使用 Elasticsearch 7:下载历史版本 Elasticsearch 7:文档唯一性 Elasticsearch 7:默认端口与端口设置 Elasticsearch 7:创建和删除索引 Elasticsearch 7:自定义 mapping 和 settings Elasticsearch 7:设置索引副本数量和分片数量 Elasticsearch 7:查看所有索引 Elasticsearch 7:数据类型 Elasticsearch 7:字符串类型 keyword 、text Elasticsearch 7:数组 Elasticsearch 7:添加和更新文档 Elasticsearch 7:通过 _bulk 批量添加文档 Elasticsearch 7:使用 from 、size 进行分页查询 Elasticsearch 7:查询中使用 sort 进行排序 Elasticsearch 7:查询结果只展示部分字段 Elasticsearch 7:查询结果中展示 _version 字段 Elasticsearch 7:使用 ignore_above 限制字符串长度 Elasticsearch 7:动态映射 Elasticsearch 7:doc_values 属性 Elasticsearch 7:刷新周期 refresh_interval Elasticsearch 7:使用 _refresh 刷新索引 Elasticsearch 7:分片(shard)限制 Elasticsearch 7:使用 _cat thread_pool 查询线程池运行情况 Elasticsearch 7:事务日志 translog Elasticsearch 7:文档 _id 的长度限制 Elasticsearch 7:分片 shard Elasticsearch 7:滚动查询 Elasticsearch 7:聚合查询 Elasticsearch 7:索引模板 Elasticsearch 7:获取文档所属的 shard Elasticsearch 7:获取版本号 Elasticsearch 7:获取指定 shard 中的文档 Elasticsearch 7:获取 shard 统计信息 Elasticsearch 7:搜索实战 Elasticsearch 7:Python 客户端 Elasticsearch 7:Java TransportClient API 客户端 Elasticsearch 7:Java REST Client API 客户端 Elasticsearch:将 SQL 转换为 DSL Elasticsearch 6 快速上手 Elasticsearch 5 快速上手 Elasticsearch 5:禁止自动创建索引 Elasticsearch 5:禁止动态增加字段 Elasticsearch 产品版本支持周期 基于 Elasticsearch 的站内搜索引擎实战

Elasticsearch 7:事务日志 translog


#Elasticsearch#


ES 基于 Lucene 实现索引数据和查询数据,Lucene 在 commit 时才会将数据写入磁盘。

以索引数据为例:

  1. 数据写入Lucene 内存,返回索引数据成功。
  2. 到一定程度后,Lucene 进行 commit,将内存内容flush到磁盘。

可能会出现,返回成功了,但是 commit 失败(比如断电),从而导致数据丢失。

ES 提供了事务日志(transaction log, 简写为 translog),保障数据不丢失。

  1. 数据写入Lucene 内存,然后写入 translog 成功,此时才会返回索引数据成功。
  2. 到一定程度后,Lucene 进行 commit,将内存内容flush到磁盘。

tranlog 默认是直接写磁盘的,所以即使因为断电等原因 Lucene commit 失败,也可以恢复数据。

配置介绍:

配置 说明
index.translog.durability 默认为 request,每一次数据修改请求,都会将对应 translog 刷盘。这是最稳妥的一个配置,不会丢数据,但性能稍差。
另一个配置是async,每隔一段时间进行一次刷盘操作,时间间隔配置在index.translog.sync_interval中。
index.translog.sync_interval translog 刷盘间隔时间。默认5s,不能小于100ms
index.translog.flush_threshold_size 当需要从 translog 恢复数据时,如果 translog 太长,会导致恢复时间过长。
该配置可以设置当 translog 达到多大时,Lucene 进行一次 commit 刷盘操作。这样可以保证最坏的情况下恢复数据,对应鹅 translog 的最大大小。默认为 512mb 。

( 本文完 )