How did we list one branch of each chain restaurant in Elasticsearch for Trendyol Meal search?
Solution: Double Query

After the first attempt, we did not get successful results, so the team got together to brainstorm. Thanks to brainstorming, a lot of useful ideas came out.

Finally, we tried to send 2 requests to Elasticsearch. We didn’t try this solution at first because we thought this method would be more costly than collapse. The solution works like this: In the Elasticsearch response of the first query, we detect the ids of the restaurants we did not want in the API response. We add these ids with must_not to the second query. Thus, only 1 branch of each chain restaurant came in the response of the second query. Thanks to this solution we didn’t break the pagination.

Finally, we are prepared to load test.

As-is Meal Search API Load Test

Meal Search API with Double Query

The response time of endpoint and number of queries, where we use this method, has increased 2 times. But API response time has not changed much.

So now, users can see the 1 branch of each chain restaurant.
['Mustafa Akilli']
['Meal', 'Elasticsearch', 'Search']