Hi again, I have a question regarding Multisearch...
# community-help
o
Hi again, I have a question regarding Multisearch with Union and pagination. Today the documentation gives this example:
Copy code
curl 'http://localhost:8108/multi_search?page=1&per_page=10' -X POST \
     -H "X-TYPESENSE-API-KEY: ${TYPESENSE_API_KEY}" -d '
{
  "union": true,
  "searches": [
    {
      "collection": "products",
      "q": "wireless headphones",
      "query_by": "name,description"
    },
    {
      "collection": "articles",
      "q": "wireless headphones",
      "query_by": "title,content"
    }
  ]
}'
Passing page/per_page in the URL looks a bit strange in that payload IMHO. Is there a way to pass them in the JSON payload?
f
Unfortunately, you can't pass pagination parameters like
page
and
per_page
in the JSON payload when using multisearch with the union option. These need to be included in the URL query string instead. When a request comes in, the system first processes the URL query parameters (like
page
,
per_page
, etc.), and then it processes the JSON body separately. For union searches, only certain settings (like
union
and
remove_duplicates
) are pulled from the JSON body. Pagination settings, however, are ignored in the body and are expected to be part of the URL query. So, when Typesense runs the union search, it uses the parameters from the URL, not the JSON body. The pagination options are designed to be global for the entire search (like one
page
value for the whole union), rather than being applied to each individual search in the union. This keeps things simpler and avoids any confusion with different pagination values for each search.
🙏 1
o
Well, the thing is that we pass pagination parameters in the JSON body when using multi-search without union, so I thought this would make sense:
Copy code
{
    "union":true,
    "page": 1,
    "per_page": 2,
    "searches": [...]
}
But I also understand your point of view.
f
URL parameters are meant to override the `searches`' search parameters. Going with this approach would lead to breaking changes / redundant ways to pass in global parameters, since we'd have to implement every valid parameter
👍 1