Search code examples
javascriptnode.jselasticsearchmongoosemongoosastic

Search multiple collections with mongoosastic


In a Node.js application, i am using Mongoosastic to retrieve data from ElasticSearch :

Article.search({
  "match_all": {}
}, function (err, results) {
  console.log(results.hits.hits);
  Post.search({
    "match_all": {}
  }, function (err, results) {
    console.log(results.hits.hits);
    return next();
  });
});

Here i am making two requests to retrieve data from two different collections. I would like to know if it was the good way to do it ?

Is it possible to search data from the two collections (or multiple collections) in one single request ? (with the multi search API for example, but with Mongoosastic).

Thank you.


Solution

  • Looks like we can't do it with Mongoosastic.

    In fact, the project define itself in the GitHub page as :

    a mongoose plugin that can automatically index your models into elasticsearch

    So i use it to define my indexes, but to do search queries it works fine with the official javascript client.

    The same question here : https://github.com/mongoosastic/mongoosastic/issues/41