Typesense Error: "Only up to 3 sort fields allowed...
# community-help
s
Typesense Error: "Only up to 3 sort fields allowed" When Combining Restaurant/Menu Item Searches Context: We have a
searchGlobally
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?
j
Could you share a set of curl commands like this that replicates the issue you're seeing: https://gist.github.com/jasonbosco/7c3432713216c378472f13e72246f46b
s
@Jason Bosco i am using the npm package not directly accessing the api so if that's ok i am calling the this search method on both cases
Copy code
search(searchParameters: SearchParams | SearchParamsWithPreset, { cacheSearchResultsForSeconds, abortSignal, }?: SearchOptions): Promise<SearchResponse<T>>;
j
The JS package is just a thin wrapper around the SDK. It's hard to debug without knowing the exact parameters you're using. If you look at the "Shell" tab in the code examples in the docs, you should find equivalent curl commands. Or the gist above also has some sample curl commands that you can adapt to help reproduce the issue
s
curl "<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 case
j
So the issue you're seeing is that a search with just two sort_by fields throws an error?
I'd also recommend sending the actual curl request to your Typesense node to see if you're able to replicate the issue. We need to essentially isolate if the issue is in Typesense Server, or in the SDK or in your application
s
Hi @Jason Bosco, sorry for the delay — I’ve tested it with parallel curl requests and it works perfectly.
👍 1