{"record":{"id":"a99331071bfaf95b","repo":"medusajs/medusa","slug":"medusa-search-accepts-at-most-max-multi-queries","errorCode":null,"errorMessage":"Medusa search accepts at most ${MAX_MULTI_QUERIES} queries per multi-query; this search needs ${queries.length}","messagePattern":"Medusa search accepts at most (.+?) queries per multi-query; this search needs (.+?)","errorType":"validation","errorClass":"MedusaError","httpStatus":400,"severity":"error","filePath":"packages/modules/search/src/providers/search-medusa/services/medusa-search.ts","lineNumber":235,"sourceCode":"  ): Promise<SearchTypes.SearchResult> {\n    const plan = buildIndexPlan(input.index)\n    const base = buildQueryPlan(input, plan)\n    const facets = buildFacetQueries(input, plan)\n    const includeCount = input.search_options?.count !== \"none\"\n    const queries: IndexQuery[] = [base.query]\n    const countIndex = includeCount ? queries.length : -1\n\n    if (includeCount) {\n      queries.push({\n        aggregate_by: { count: [\"Count\"] },\n        filters: base.query.filters,\n      })\n    }\n    const facetOffset = queries.length\n    queries.push(...facets.map((facet) => facet.query))\n\n    if (queries.length > MAX_MULTI_QUERIES) {\n      throw new MedusaError(\n        MedusaError.Types.NOT_ALLOWED,\n        `Medusa search accepts at most ${MAX_MULTI_QUERIES} queries per multi-query; this search needs ${queries.length}`\n      )\n    }\n\n    const response = await this.index(input.index.physical_name).multiQuery({\n      queries,\n      consistency: base.options.consistency\n        ? { level: base.options.consistency }\n        : undefined,\n    })\n    const hitResult = response.results[0]\n    const rows = (hitResult?.rows ?? []).slice(base.skip, base.skip + base.take)\n    const parsedFacets = parseFacetResults(\n      facets,\n      response.results.slice(facetOffset)\n    )\n","sourceCodeStart":217,"sourceCodeEnd":253,"githubUrl":"https://github.com/medusajs/medusa/blob/5e06e544a296b9033f20f71f11c559f81a0e5739/packages/modules/search/src/providers/search-medusa/services/medusa-search.ts#L217-L253","documentation":"The Medusa search provider caps how many individual queries a single multi-query request can contain. Every facet range, facet value, and the main query counts toward MAX_MULTI_QUERIES, and this error is thrown when the assembled multi-query batch exceeds that provider limit.","triggerScenarios":"Calling searchMany (or the provider search path that fans out into a multiQuery) with many facet requests, especially range facets that expand into one query per range bucket, plus additional facet value queries, so queries.length > MAX_MULTI_QUERIES.","commonSituations":"Storefront filter UIs requesting many range buckets (e.g. price ranges sliced into many intervals) or large numbers of faceted fields in one search request; copying a Meilisearch-style facet config with dozens of facets into search_options.facets.","solutions":["Reduce the number of facet requests in search_options.facets (drop unused facets or fetch them across separate searches)","If using range facets, consolidate range buckets so each facet contributes fewer sub-queries","Precompute total query count (1 + sum of ranges + value facets) and cap it client-side before calling search"],"exampleFix":"// before\nconst result = await query.graph({\n  entity: \"product\",\n  filters: { q: \"shirt\" },\n  pagination: {},\n  // ...options with many facets\n})\n// limit facets / range buckets\nconst facets = [...allFacets].slice(0, 5)\n","handlingStrategy":"validation","validationCode":"const MAX_MULTI_QUERIES = 50 // keep in sync with provider constant\nfunction estimateQueryCount(facets) {\n  return (\n    1 +\n    facets.reduce(\n      (n, f) => n + (f.type === \"range\" ? f.ranges.length : 1),\n      0\n    )\n  )\n}\nif (estimateQueryCount(facets) > MAX_MULTI_QUERIES) {\n  facets = facets.slice(0, MAX_MULTI_QUERIES - 1)\n}","typeGuard":"const isFacetRequest = (f) =>\n  typeof f?.field === \"string\" &&\n  (f.type === \"range\" ? Array.isArray(f.ranges) && f.ranges.length > 0 : true)","tryCatchPattern":"try { await search(...) } catch (e) { if (e instanceof MedusaError && e.type === \"not_allowed\" && /at most/.test(e.message)) { /* drop facets and retry once without facets */ } throw e }","preventionTips":["Count queries client-side: 1 + every range bucket + every value facet","Slice facet lists to a fixed budget before sending","Cache facet counts separately so not every search needs all facets"],"tags":["search","facets","limits","multi-query"],"backgroundTag":"query-limit-exceeded","analyzedSha":"5e06e544a296b9033f20f71f11c559f81a0e5739","analyzedAt":"2026-08-27T07:24:39.599Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}