solomon mulatu
05/08/2025, 7:53 AMsearchGlobally
endpoint that calls two Typesense searches:
1. executeRestaurantSearch
2. executeMenuItemSearch
Problem:
- ✅ Both service calls work individually (tested by commenting out one at a time).
- ❌ When called together, we get a 400
error:
"Request failed with HTTP code 400 | Server said: Only upto 3 sort fields are allowed."
async searchGlobally(
@Args() { params, location, maximumDeliveryTime }: SearchEngineSearchDefaultMenuItemRequestDto
) {
const restaurantSearchResponse = await this.searchEngineService.executeRestaurantSearch(params, location, maximumDeliveryTime);
const menuItemSearchResponse = await this.searchEngineService.executeMenuItemSearch(params, location, maximumDeliveryTime);
// ... return combined results
}
Suspected Cause:
- The params
object passed to both services is shared/mutated, causing unintended sort field accumulation.
- Example: If executeRestaurantSearch
adds 2 sort fields and executeMenuItemSearch
adds 2 more, the second call might inherit the first’s sort fields.
What We’ve Tried:
1. Validated that each service works in isolation.
2. Confirmed that params
is not explicitly modified in the controller.
Questions:
1. Has anyone encountered this "3 sort fields" limitation in Typesense when chaining queries?
2. How can we ensure params
(especially sort_by
) is isolated between service calls?
- Should we deep-clone params
before passing to each service?
- Or is there a configuration in `executeRestaurantSearch`/`executeMenuItemSearch` that might be appending sort fields?Jason Bosco
05/08/2025, 2:59 PMsolomon mulatu
05/08/2025, 6:00 PMsearch(searchParameters: SearchParams | SearchParamsWithPreset, { cacheSearchResultsForSeconds, abortSignal, }?: SearchOptions): Promise<SearchResponse<T>>;
Jason Bosco
05/08/2025, 6:01 PMsolomon mulatu
05/08/2025, 6:06 PMcurl "<https://TYPESENSE_HOST/collections/restaurants/documents/search>" \
-X POST \
-H "X-TYPESENSE-API-KEY: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "*",
"query_by": "name,description",
"filter_by": "restaurantAvailable:=true",
"sort_by": "location(12.34, 56.78):asc, _text_match:desc",
"per_page": 20
}'
and
"https://TYPESENSE_HOST/collections/menuitems/documents/search" \
-X POST \
-H "X-TYPESENSE-API-KEY: YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"q": "*",
"query_by": "name,description",
"filter_by": "restaurantAvailable:=true",
"sort_by": "location(12.34, 56.78):asc, _text_match:desc",
"per_page": 20
}'
those are the alternative curl for the methods i call in each caseJason Bosco
05/08/2025, 7:03 PMJason Bosco
05/08/2025, 7:04 PMsolomon mulatu
05/10/2025, 6:07 AMHi @Jason Bosco, sorry for the delay — I’ve tested it with parallel curl requests and it works perfectly.