首页  

elasticsearch5.0刷新机制     所属分类 elasticsearch 浏览量 1802
根据原文翻译整理
https://www.elastic.co/guide/en/elasticsearch/reference/5.0/docs-refresh.html


refresh  刷新 

The Index, Update, Delete, and Bulk APIs support setting refresh to control 
when changes made by this request are made visible to search. 

索引 更新 删除 批量操作接口支持 refresh 选项
用于控制写入请求是否立即对搜索可见


Empty string or true
wait_for
false (the default)


true 
Refresh the relevant primary and replica shards (not the whole index) immediately 
after the operation occurs, so that the updated document appears in search results immediately. 

立即刷新相关的主分片和复本分片(不是整个索引),操作完成后,更新后的文档立即出现在搜索结果中。

This should ONLY be done after careful thought and verification 
that it does not lead to poor performance, both from an indexing and a search standpoint.
仔细思考和验证
谨慎使用,会影响索引和搜索性能


wait_for

Wait for the changes made by the request to be made visible by a refresh before replying. 
This doesn’t force an immediate refresh, rather, it waits for a refresh to happen. 
Elasticsearch automatically refreshes shards that have changed every index.refresh_interval 
which defaults to one second. That setting is dynamic. 
Calling the Refresh API or setting refresh to true on any of the APIs 
that support it will also cause a refresh, 
in turn causing already running requests with refresh=wait_for to return.

在回复之前,等待刷新将请求所做的更改变为可见。这并不强制立即刷新,而是等待刷新发生。

么个索引可设置刷新时间间隔 index.refresh_interval 默认值是1秒。该设置是动态的。

在任何API上调用Refresh API或将Refresh设置为true 会导致刷新
从而导致使用refresh=wait_for的请求返回。

默认 为 false 
Take no refresh related actions. 
The changes made by this request will be made visible at some point after the request returns.

默认刷新时间间隔 1秒, 刷新之后 写入 对搜索可见


Choosing which setting to use

默认使用 false
如果必须让请求所做的更改与请求同步可见,必须在将更多的负载放在ES (true)和等待响应(wait_for)之间进行选择。
一些关键点

The more changes being made to the index the more work wait_for saves compared to true. 
In the case that the index is only changed once every index.refresh_interval then it saves no work.

对索引所做的更改越多,wait_for比true 更省cpu
如果在刷新时间间隔内,索引只发生一次变化, 两者效果一样

true creates less efficient indexes constructs (tiny segments) 
that must later be merged into more efficient index constructs (larger segments). 
Meaning that the cost of true is payed at index time to create the tiny segment, 
at search time to search the tiny segment, and at merge time to make the larger segments.

使用true 时 会创建低效的段(小段),之后会合并成高效的段(大段)
使用true的代价 
创建低效的小段  搜索小段 将小段合并成大段




Never start multiple refresh=wait_for requests in a row. 
Instead batch them into a single bulk request with refresh=wait_for 
and Elasticsearch will start them all in parallel 
and return only when they have all finished.

不要在一行中启动多个wait_for请求。批处理 和 wait_for 结合使用,
ES会并行执行,当它们全部完成时返回。


If the refresh interval is set to -1, disabling the automatic refreshes, 
then requests with refresh=wait_for will wait indefinitely until some action causes a refresh. 
Conversely, setting index.refresh_interval to something shorter than the default like 200ms 
will make refresh=wait_for come back faster, but it’ll still generate inefficient segments.

如果刷新间隔设置为-1,则禁用自动刷新,那么wait_for的请求将无限期地等待,直到某个操作导致刷新。
相反,讲refresh_interval设置为更小值(如200ms),wait_for返回更快,但会生成低效的段。



wait_for只影响当前请求, true 会影响其他请求



实际案例


These will create a document and immediately refresh the index so it is visible:

PUT /test/test/1?refresh
{"test": "test"}
PUT /test/test/2?refresh=true
{"test": "test"}

These will create a document without doing anything to make it visible for search:

PUT /test/test/3
{"test": "test"}
PUT /test/test/4?refresh=false
{"test": "test"}

This will create a document and wait for it to become visible for search:

PUT /test/test/4?refresh=wait_for
{"test": "test"}

上一篇     下一篇
elasticsearch5.0批量更新API

elasticsearch5.0重建索引API

elasticsearch5.0词向量信息查询接口

linux之grep命令

elasticsearch5.0搜索API概述

elasticsearch5.0搜索API使用概述