How to make join among indexes on ES

Hi guys,

I need help with some changes we need to do to the API. Basically, we have two indexes exposed (Products, Suppliers) and we need to make a join between products and suppliers.

Our indexes is made as follow:

Product Index:
{
“_index”: “XXX”,
“_type”: “product”,
“_id”: “73”,
“_score”: 1,
“_source”: {
“attribute_set_id”: 4,
“created_at”: “XXX”,
“updated_at”: “XXX”,
“type_id”: “simple”,
“sku”: “XXX”,
“id”: 73,
“media_gallery”: [],
“brand”: “XXX”

}

Supplier Index:
{
“_index”: “”,
“_type”: “supplier”,
“_id”: “5”,
“_score”: 1,
“_source”: {
“store_id”: “1”,
“firstname”: “XXX”,
“lastname”: “XXX”,
“email”: “XXX”,
“shipping_rates”: {
“standard_delivery”: [],
“fast_delivery”: []
},
“GMT”: null,
“products”: [1,3,4]
}
}

We need to make a subquery into the main products query (list, single, etc) to add the suppliers to the product where the product id is present on the products array (of the supplier index). It’s very similar to what it’s being done with the categories.

Thanks guys,
I’d really appreciate your help.

Elasticsearch is not a relational database. If you want to have certain suppliers in the product just put them in the product index as a suppliers field (array). Otherwise, you would just need to make 2 requests. One for the product, then compute matching suppliers and another request for suppliers

Ok, understand. That’s actually what we end up doing. At first, we integrated the Supplier call to the Product call, but it was inefficient since it doesn’t allow us to query that related data. So at the end, we decided to add the data to the Product index itself, so we can query it. We couldn’t come up with anything better.

Thanks bud,

Just for curiosity, but how does the category and attributes work? I mean, how can i reproduce the same result. Thanks again