How to deal with Elasticsearch index delay

前端 未结 4 453
臣服心动
臣服心动 2020-12-09 08:45

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 docu

4条回答
  •  无人及你
    2020-12-09 09:32

    Here is a fragment of code which is what I did in my Angular application to cope with this. In the component:

    async doNewEntrySave() {
        try {
          const resp = await this.client.createRequest(this.doc).toPromise();
          this.modeRefreshDelay = true;
          setTimeout(() => {
            this.modeRefreshDelay = false;
            this.refreshPage();
          }, 2500);
        } catch (err) {
          this.error.postError(err);
        }
      }
    

    In the template:

    Waiting for update ...

    I understand this is a quick-and-dirty solution but it illustrates how the user experience should work. Obviously it breaks if the real-world latency turns out to be more than 2.5 seconds. A fancier version would loop until the new record showed up in the page delay (with a limit of course).

    Unless you completely redesign ElasticSearch you will always have some latency between the successful index operation and the time when that document shows up in search results.

提交回复
热议问题