es 更新延迟问题

es 更新延迟问题

es 近实时搜索

瞎解释

详情还是看上面的说明吧,总而言之,es在更新之后并不是立即可见(可查询)的,会有1s的延迟,可以通过设置refresh_interval参数来修改刷新的间隔。

但是在实际应用中,1s的延迟已经算是很久了,在java high level client中,为indexinsertupdatebulk 提供了setRefreshPolicy方法,用于设置数据更改后的刷新策略。

主要是三个参数IMMEDIATENONEWAIT_UNTIL

  1. NONE:
    Don’t refresh after this request. The default.
    这是默认的一种方式,调用request修改以后,并不进行强制刷新,刷新的时间间隔为refresh_interval设置的参数。设置方式有以下两种。
// 1.
request.setRefreshPolicy(WriteRequest.RefreshPolicy.NONE);
// 2.
request.setRefreshPolicy("false");
  1. IMMEDIATE
    强制刷新相关的主分片和副分片(而不是整个索引),使更新的分片状态变为可搜索。在使用之前,一定要仔细考虑使用该参数会不会导致性能不佳。
    Force a refresh as part of this request. This refresh policy does not scale for high indexing or search throughput but is useful to present a consistent view to for indices with very low traffic. And it is wonderful for tests!
    强制刷新作为请求的一部分。这种方式并不适用于索引和查询高吞吐量的场景,但是作为流量小时提供一致性的视图的确是很使用的。一般用来测试…?使用方式:
// 1.
request.setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE);
// 2.
request.setRefreshPolicy("true");
  1. WAIT_UNTIL:
    在返回请求结果之前,会等待刷新请求所做的更改(类似于阻塞…?)。并不是强制立即刷新,而是等待刷新发生。Elasticsearch会自动刷新已更改每个index.refresh_interval的分片,默认为一秒。该设置是动态的。
    Leave this request open until a refresh has made the contents of this request visible to search. This refresh policy is compatible with high indexing and search throughput but it causes the request to wait to reply until a refresh occurs.
    请求持续为打开状态,知道修改的内容变为可搜索为止。此刷新策略与高索引和搜索吞吐量兼容,但它会导致请求等待回复,直到刷新发生。使用方式:
// 1.
request.setRefreshPolicy(WriteRequest.RefreshPolicy.WAIT_UNTIL);
// 2.
request.setRefreshPolicy("wait_for");

more

强烈建议看看
6.4 doc ?refresh

参考:
WriteRequest.RefreshPolicy API

  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值