[英]Elastic Search GET doesn't give latest document
I am using Elastic 5.1.2 version. 我正在使用Elastic 5.1.2版本。 I am using Elastic java Restclient for posting and query the documents from Elastic search.
我正在使用Elastic java Restclient从Elastic搜索中发布和查询文档。
I am not getting the accurate count of documents when i use GET operation immediately after the POST operation. POST操作后立即使用GET操作时,我没有得到准确的文档计数。 If i sleep for > 1 sec between POST and GET, then the GET operation is able to give the accurate count.
如果我在POST和GET之间睡眠> 1秒,则GET操作能够给出准确的计数。
My flow of operations are: 1) post a new transaction(document) using POST operation. 我的操作流程是:1)使用POST操作过帐新事务(文档)。 2) retrieve the count of total documents using GET operation.
2)使用GET操作检索文档总数。 this is immediately after the POST.
这是在POST之后。
I am thinking that, Elastic is taking time to update the index. 我认为,Elastic需要时间来更新索引。 Is this a problem with Elasticsearch or with any of my settings.
这是Elasticsearch还是我的任何设置有问题吗? 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: 如果这困扰您,您有几种选择:
/_refresh
endpoint after POSTing your documents and that will immediately refresh your index and the next GET call will work /_refresh
文档后调用/_refresh
端点 ,这将立即刷新索引,并且下一个GET调用将起作用 ?refresh=true
parameter in your POST call when you index documents and that will basically do the same as 1 ?refresh=true
参数 ,该参数基本上与1相同 ?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 ?refresh=wait_for
参数 ,并且仅在进行刷新操作时该调用才会返回,以便下一个GET调用将返回文档 index.refresh_interval
in your settings (defaults to 1 second) so that the refresh operations happen more often. index.refresh_interval
(默认为1秒),以便刷新操作更频繁地发生。 Just know that from a performance standpoint, the least aggressive way of achieving what you want is 3, ie 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. 只是知道,从性能的角度来看,实现所需目标的最不积极的方法是3,即ES 5中引入的新参数,该参数不会强制刷新索引,只有在新索引文档可用时才会返回搜索。 Forcing a refresh too often (1, 2 and 3) can kill your performance.
过于频繁地刷新(1、2和3)会降低性能。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.