如何处理弹性搜索索引延迟 [英] How to deal with Elasticsearch index delay

查看:130
本文介绍了如何处理弹性搜索索引延迟的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的方案:



我有一个包含用户列表的页面。我通过我的Web界面创建一个新用户并将其保存到服务器。服务器使用弹性搜索索引文档并成功返回。然后我被重定向到不包含新用户的列表页面,因为文件可能需要长达1秒的时间才能在弹性搜索中搜索



< a href =https://www.elastic.co/guide/en/elasticsearch/guide/current/near-real-time.html>在弹性搜索中接近实时搜索。



弹性搜索指南说您可以手动刷新索引,但表示不在生产中执行此操作。


...每次在生产中索引文档时都不要手动刷新;它会伤害你的表现。相反,您的应用程序需要了解Elasticsearch的近乎实时的性质,并为其提供补贴。


我想知道其他人如何解决这个问题?我希望有一件事情或者我可以听的东西,当文档可用于搜索时会告诉我,但似乎没有这样的东西。简单的等待1秒是合理的,但似乎是一个坏主意,因为它可能需要的时间要少得多。



谢谢!

解决方案

即使您可以强制ES自行刷新,您已经正确注意到可能会损害性能。一个解决这个问题的方法和人们经常做的(我自己包括的)是给出一个实时的错觉。最后,它只是一个UX挑战,而不是真正的技术限制。



当重定向到用户列表时,您可以人为地包括您所拥有的新记录刚刚创建到用户列表中,就像该记录是由ES本身返回的一样。没有什么可以阻止你这样做。当你决定刷新页面时,新的用户记录将被ES正确地返回,没有人关心这个记录来自哪里,所有用户关心的是那时他是想看新的记录他只是创建了,只是因为我们习惯于顺序地思考。



另一种实现这一点的方法是通过重新加载空的用户列表框架,然后通过Ajax或其他异步方式,检索用户列表并显示它。



另一种方法是在UI上提供一个视觉提示/线索,在后台发生了一些事情,并且很快就会期待更新。 >

最后,这一切都归结为用户的惊喜,但是给他们足够的线索,发现了什么,发生了什么,还有什么他们应该会发生的事情。 p>

Here's my scenario:

I have a page that contains a list of users. I create a new user through my web interface and save it to the server. The server indexes the document in elasticsearch and returns successfully. I am then redirected to the list page which doesn't contain the new user because it can take up to 1-second for documents to become available for search in elasticsearch

Near real-time search in elasticsearch.

The elasticsearch guide says you can manually refresh the index, but says not to do it in production.

...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.

I'm wondering how other people get around this? I wish there was an event or something I could listen for that would tell me when the document was available for search but there doesn't appear to be anything like that. Simply waiting for 1-second is plausible but it seems like a bad idea because it presumably could take much less time than that.

Thanks!

解决方案

Even though you can force ES to refresh itself, you've correctly noticed that it might hurt performance. One solution around this and what people often do (myself included) is to give an illusion of real-time. In the end, it's merely a UX challenge and not really a technical limitation.

When redirecting to the list of users, you could artificially include the new record that you've just created into the list of users as if that record had been returned by ES itself. Nothing prevents you from doing that. And by the time you decide to refresh the page, the new user record would be correctly returned by ES and no one cares where that record is coming from, all the user cares about at that moment is that he wants to see the new record that he's just created, simply because we're used to think sequentially.

Another way to achieve this is by reloading an empty user list skeleton and then via Ajax or some other asynchronous way, retrieve the list of users and display it.

Yet another way is to provide a visual hint/clue on the UI that something is happening in the background and that an update is to be expected very shortly.

In the end, it all boils down to not surprise users but to give them enough clues as to what has happened, what is happening and what they should still expect to happen.

这篇关于如何处理弹性搜索索引延迟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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