1

Database: MongoDB, Server: Nodejs

I have around 10 collections on my MongoDB database, Can I able to query on those collections at the same time with Elasticsearch and return appropriate results?

examples queries send from users

  • sort collections for the lastest created post on all collections
  • full-text search on all collections
U.A
  • 2,991
  • 3
  • 24
  • 36

2 Answers2

1

If you are using Elasticsearch version lower than 6.X, then you can have multiple types(collection in your case) in a single Elasticsearch index.

for example, if twitter is your index, you can have tweets, users, employees, user-profiles so on, in single elasticsearch index and searching on twitter index will internally search in all these types.

But if you are using Elasticsearch index greater than 6.X and use the different index for storing these collections, then can you use the multiple indices in your query as explained in the Elasticsearch docs.

Amit
  • 30,756
  • 6
  • 57
  • 88
  • 1
    can I able to create types for all my categories(eg: vehicles, cloths) inside a single index and use one query to search across all of the types? – U.A Apr 06 '20 at 12:49
  • 2
    yes, if you are using below ES 6.X :), although wouldn't recommend that as latest version is 7.6 and these `types` have been deprecated and will be removed in soon to release 8.X , so later on when you upgrade your ES you will face a lot of issues, instead you can use the multiple indices API to search on your multiple indices specific to each collection in your case :) – Amit Apr 06 '20 at 12:50
0

You can create separate indices for each collection and use aliases to query all of them.

Regarding querying lastest created post on all collections, depending on your use case, you can use single index per collection or create index by day/month to partition data.