Elastic Search GET 不提供最新文档 [英] Elastic Search GET doesn't give latest document

查看:22
本文介绍了Elastic Search GET 不提供最新文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Elastic 5.1.2 版本.我正在使用 Elastic java Restclient 发布和查询来自 Elastic 搜索的文档.

I am using Elastic 5.1.2 version. I am using Elastic java Restclient for posting and query the documents from Elastic search.

当我在 POST 操作后立即使用 GET 操作时,我没有得到准确的文档计数.如果我在 POST 和 GET 之间睡眠 > 1 秒,则 GET 操作能够给出准确的计数.

I am not getting the accurate count of documents when i use GET operation immediately after the POST operation. If i sleep for > 1 sec between POST and GET, then the GET operation is able to give the accurate count.

我的操作流程是:1) 使用 POST 操作发布一个新的交易(文档).2) 使用 GET 操作检索总文档数.这是在 POST 之后.

My flow of operations are: 1) post a new transaction(document) using POST operation. 2) retrieve the count of total documents using GET operation. this is immediately after the POST.

我在想,Elastic 正在花时间更新索引.这是 Elasticsearch 的问题还是我的任何设置的问题.请帮忙

I am thinking that, Elastic is taking time to update the index. Is this a problem with Elasticsearch or with any of my settings. Please help

推荐答案

这是正常行为!当您索引新数据时,它不会立即可用,而是会在下一次刷新之后(默认情况下每秒发生一次).

That's normal behavior! When you index new data it isn't immediately available, but will be after the next refresh which happens once every second by default.

如果这让您感到困扰,您有几个选择:

If that bothers you, you have a few options:

  1. 您可以调用/_refresh 端点 发布您的文档后,它将立即刷新您的索引,下一个 GET 调用将起作用
  2. 您可以添加?refresh=true 参数 在您索引文档时的 POST 调用中,这基本上与 1 相同
  3. 您可以添加?refresh=wait_for 参数 在您索引文档时的 POST 调用中,并且该调用仅在发生刷新操作时返回,以便下一次 GET 调用将返回文档
  4. 您可以减少设置中的 index.refresh_interval(默认为 1 秒),以便更频繁地进行刷新操作.
  1. you can call the /_refresh endpoint after POSTing your documents and that will immediately refresh your index and the next GET call will work
  2. you can add the ?refresh=true parameter in your POST call when you index documents and that will basically do the same as 1
  3. you can add the ?refresh=wait_for parameter in your POST call when you index documents and the call will only return when the refresh operation has occurred, so that the next GET call will return the documents
  4. you can decrease the index.refresh_interval in your settings (defaults to 1 second) so that the refresh operations happen more often.

只要知道从性能的角度来看,实现您想要的最不激进的方式是 3,即这是 ES 5 中引入的一个新参数,它不会强制刷新您的索引,但只会在新索引的文档中返回可供搜索.过于频繁地强制刷新(1、2 和 3)会影响您的表现.

Just know that from a performance standpoint, the least aggressive way of achieving what you want is 3, i.e. that's a new parameter introduced in ES 5 that will not force a refresh on your index but will only return once the newly indexed documents are available for search. Forcing a refresh too often (1, 2 and 3) can kill your performance.

这篇关于Elastic Search GET 不提供最新文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆