On the combination of mongodb and elasticsearch

  mongodb, question

Suppose I need to search for articles based on titles and tags.

  1. Index problem
    After indexing the titles and tags of articles in elasticsearch, is it necessary to index the titles and tags of articles in mongodb? Because the id of the article can be obtained in elasticsearch, and then the article id can be directly used for query. In this case, is it only necessary to index the article id?

  2. Pagination problem
    When I am not using elasticsearch, I am usingThe method hereImplementation of paging. Implementation is cumbersome because you need to get currentId and currentPage to page.
    If elasticsearch is used, paging can be realized directly through from/size, but it will return size ids and then conduct size queries through mongodb. In other words, there will be size queries in one paging. The original method should have only one query. I don’t know which method is better.

  1. If the search is done in elasticsearch, there is no need to index the title or label in mongodb. The article id should have an index by default, if you use the _id field
  2. You can use {_id: {$in: [size id arrays]}} queries to get size documents at a time.