Home > Blockchain >  How can I get information from 2 different ElasticSearch indexes?
How can I get information from 2 different ElasticSearch indexes?

Time:10-17

So, I have 2 indexes in my Elasticsearch server. I need to gather the results from the first index, and for each result I need to gather info from the second index.

How to do that? Tried the foreach processor, but no luck so far.

Tky

CodePudding user response:

The foreach processor is for ingest pipelines, meaning, stuff that gets done at indexing time. So it won't help you when you are trying to gather the results.

In general, it's not going to be possible to query another index (which might live on another shard) from within a query.

In some cases, you can use a join field. There are performance implications, it's only recommended in specific cases.

If you are not in the join field use case, and you can restructure your data to use nested objects, it will be more performant than join fields.

Otherwise, you'll be better off running multiple queries in the application code (maybe you can fetch all the "secondary" results using just one query, so you'd have 2 queries in total?)

CodePudding user response:

I need to gather the results from the first index, and for each result I need to gather info from the second index.

Unless you create parent/child relationships, that's not possible in ElasticSearch.

However, note:

In Elasticsearch the key to good performance is to de-normalize your data into documents. Each join field, has_child or has_parent query adds a significant tax to your query performance.

Handle reading from multiple indexes within your application or rethink your index mapping.

  • Related