nha*_*aud 7 optimization performance elasticsearch
我需要在Elasticsearch中索引/更新文档并等待它可搜索(刷新已完成).Github上有一个相关的问题:https://github.com/elasticsearch/elasticsearch/issues/1063
我不会强制刷新,因为它会影响索引性能,我需要经常执行此操作.我按照Github问题的描述尝试等待1秒钟.只要Elasticsearch没有压力,它就能很好地运行,但是当没有多少RAM(偶尔可能会发生)时,我看到刷新需要5到6秒.因此我尝试了另一种方式.
我在后端编写了一个辅助函数,等待"可搜索"文档达到给定版本.这很简单:
- GET the document with realtime=false
- if there is a result
- if result.version >= wanted.version.
Return
- else
wait a little more and retry
- else if the doc is not found
- HEAD the document with realtime=true (test if the doc exists in the transaction log)
- if the doc is found (then it has just been created)
wait a little more and retry
- else
Return. (the doc might have been created and deleted really fast)
Run Code Online (Sandbox Code Playgroud)
想要的版本是在索引文档时由elasticsearch返回的版本.
这个算法有效但你可以看到它远非完美.
首先它会在压力下对弹性搜索进行更多调用,这不是一个好主意.
我已经看到弹性搜索在文档被删除一段时间后重置了版本号.如果由于某种原因该函数错过了,我们可能会等到doc再次达到此版本.(这就是为什么我还添加了超时).
有人有更好的解决方案吗?现在自动缩放不是一个可接受的答案.
正如 Guillaume Mass\xc3\xa9 所说,一个解决方案即将合并到 Elasticsearch 中https://github.com/elastic/elasticsearch/issues/1063#issuecomment-223368867
\n\n因此,我建议等待内置功能,而不是实施自定义解决方案。
\n