Reputation: 1079
I am using AWS OpenSearch database which is a fork of Elasticsearch. My use case is as follows:
variations
field which is a list of IDs of all other products within the same productGroupIdMy current thinking is I am going to perform the query in 2 steps:
variations
field (some optimization can be done to minimize the number of productGroupId look ups but that’s beside the point)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
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