造成的困扰:
es在index后有一个refresh_interval默认1秒,在这个时间间隔内search是不可见的。起初并不知道这个特性,导致应用了es保存数据的业务在存储数据后立即读取却取出不到的问题。
存入数据:
19:09:27上传了一条,19:09:29上传了两条数据:
![](https://img.haomeiwen.com/i14577266/0652af452742d01f.png)
1s内立即取回,取到的是19:09:27上传的数据:
![](https://img.haomeiwen.com/i14577266/020b81f629cda8c3.png)
![](https://img.haomeiwen.com/i14577266/6b6f0ffdb7c82217.png)
解决:
将index的refresh_interval值调小:
{
"settings": {
"index": {
...
"refresh_interval": "100ms",
...
}
}
}
不过,生产环境最好不要把这个值设置得太小,因为会影响系统的性能:
...don’t do a manual refresh every time you index a document in production; it will hurt your performance. Instead, your application needs to be aware of the near real-time nature of Elasticsearch and make allowances for it.
参考
追记:
refresh_interval是索引的属性值,不要和代码里中bulk的FlushInterval值混淆了。
网友评论