Home > Software design >  How to resolve data by ID from another index?
How to resolve data by ID from another index?

Time:03-11

I'm having 2 indexes: images and gallery. gallery has only IDs of the images. Is there a way in Elasticsearch to return/resolve that data in the response? Or do I need to do 2 queries and resolve them on my own?

// image
{ id: 1, url: 'foo.bar' }
{ id: 2, url: 'foo.bar' }

// gallery
[1,2]

// result should be
[{ id: 1, url: 'foo.bar' }, { id: 2, url: 'foo.bar' }]

CodePudding user response:

Refer to Elasticsearch documentation on joining queries, but both the options are for the same index, Elasticsearch doesn't offer the sql like JOIN operation as its costly and against the design of distributed system.

Even if you choose one of the option mentioned in the documentation, it's going to be costly than normal queries, I would suggest following.

  1. If you have very less data gallary index, just the ids, then making second query isn't that costly, and in this case you don't have to change anything.
  2. If performance is your concern, you can choose one of the option and compare the performance with first option with few tests, and whichever works best for you, you can choose that. You can use the Reindex API to reindex the data in same index with required mapping.
  • Related