nxh
nxh

Reputation: 1079

Elasticsearch/OpensSearch query for product variations

I am using AWS OpenSearch database which is a fork of Elasticsearch. My use case is as follows:

My current thinking is I am going to perform the query in 2 steps:

Do you have any suggestions on how to design the search index or some queries I can use to make this more efficient?

Upvotes: 0

Views: 88

Answers (1)

Charchit Kapoor
Charchit Kapoor

Reputation: 9284

I would suggest you to create two indexes. One would keep all the product related details, and the other would keep track of all the product variations for a given productGroupId. The documents of these indices will have the following structure.

Product

{
  id: "",
  name: "",
  brand: "",
  productGroupId: ""
}

ProductGroupVariations

{ 
  id: "" //productGroupId,
  variations: [] // list of product ID's
}

Using this structure, when fetching a product, you can fetch variations, using one more call to productGroupVariations index.

Also, make sure to update the variations array, whenever a product is added, updated or deleted.

Upvotes: 0

Related Questions