How to use relationships

Hi,
I have an index of Items. Every Item belongs to another model Owner. When I search through Items index I need to have also some properties of the Owner of the Item.

My solution (HIGH IndexOPS):
I can nest these pieces of information in every Item but this creates a problem when changing an attribute of the Owner. Changing an attribute of owner means to change the same attribute on every Item related to it creating a lot of Index operations. If an Owner has 20k Items–> 20k OPS.

This could be achieved by only one OPS on Owner record. There is any solution to this?
I’ve read https://www.algolia.com/doc/guides/indexing/structuring-your-data/#indexing-relations but this only helps in searching on nested items.

Best regards,
Matteo Pennisi

Hi @matteo.pennisi98,

This is the correct way to use Algolia. The engine is design to optimize search, relevancy and performance that’s why there is no way to do some sort of sql JOIN operation.

In most usecases, the Owner doesn’t change often. If you have data like itemCount per owner, I’d recommend removing them if possible.

If you need to update the owner often, one solution would be to build a backend search implementation. Basically, you’d retrieve the best match via Algolia and then populate the owner in each record via your database. It will have a cost in term of performance, and will make InstantSearch a little but harder to use but it’s possible. It would even be possible to do this in the frontend if you prefer JavaScript.

Note that this solution will make it impossible to search inside the owner’s attribute.

Please let me know what you think.

Hi @julienbourdeau,
thanks for fast response.

So is possible to make a JOIN on Algolia? If yes please link me a guide or some code please :smiley:

For example, every item has some rating related to the Owner of the item. But rating can change multiple time so this means lots of OPS. And a user need also to filter by the rating of Items.

This solution can work but this means to create a request for every item rendered, and make impossible to filter by this parameter

I hope there is a solution to this.

Thanks,
Matteo Pennisi

Oops! I forgot the word “no” :sweat_smile: I edited my original answer.

Indeed if you don’t have the owner you won’t be able to filter. I believe the best to reduce operations, would be to only updated every X hours. The rating depending on the owner will change once a day for instance, instead of everytime a new rating is added. This is the only solution to “save” on operations.

1 Like

This is a very smart solution, I will try to solve in this way :smile:

However thanks for the time you dedicated to me, I hope that this could be helpful for someone in my same situation.

Best greetings from Italy @julienbourdeau :relaxed: