Search code examples
elasticsearchmongoosemongoosastic

Referencing to another index in elasticsearch


I am using Elasticsearch for searching the indexed documents. The documents are indexed using mongoosastic. How could i refer to another index in a query like populate in mongoose or join in SQL. Please help me with an example.

i am having two index namely project and user. In project collection of mongodb, refers to user collection of mongodb. I am searching on project using elasticsearch and getting the results. But i want to refer user index in elasticsearch in same query fired on project index. So how could i refer user index from project index.


Solution

  • I think that you should put all your data in the same index, and differentiate them by type.

    But with your current indexes, you could execute a unique query on two indexes by creating an alias. An alias can be declared on top of one or many indexes (or aliases). So in your case, create an index on top of your "user" and "project" indexes, and execute your query on the alias.

    Official doc (it's very easy to set up an alias): http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/indices-aliases.html