1 post:
2 operationId: PostSearch
3 summary: Search Indexes
4 description: >-
5 Search the indexes that your application exposes to the storefront. An index
6 is only searchable through this route once it's allowed with the
7 `configureStoreSearch` middleware, and a query for any other index is
8 answered with a `404` error. Pass a single query, or a `queries` array to
9 run a batch of queries in one round-trip to the search engine. For an index
10 whose entity is `product`, Medusa also restricts the results to published
11 products in the sales channels of the request's publishable API key.
12 externalDocs:
13 description: Learn about the Store Search API route
14 url: >-
15 https://docs.medusajs.com/resources/infrastructure-modules/search/store-search
16 x-authenticated: false
17 parameters:
18 - name: x-publishable-api-key
19 in: header
20 description: Publishable API Key created in the Medusa Admin.
21 required: true
22 schema:
23 type: string
24 externalDocs:
25 url: https://docs.medusajs.com/api/store/publishable-api-key
26 - name: x-medusa-locale
27 in: header
28 description: The locale in BCP 47 format to retrieve localized content.
29 required: false
30 schema:
31 type: string
32 example: en-US
33 externalDocs:
34 url: >-
35 https://docs.medusajs.com/resources/commerce-modules/translation/storefront
36 description: Learn more in the Serve Translations in Storefront guide.
37 - name: locale
38 in: query
39 description: The locale in BCP 47 format to retrieve localized content.
40 required: false
41 schema:
42 type: string
43 example: en-US
44 externalDocs:
45 url: >-
46 https://docs.medusajs.com/resources/commerce-modules/translation/storefront
47 description: Learn more in the Serve Translations in Storefront guide.
48 requestBody:
49 content:
50 application/json:
51 schema:
52 oneOf:
53 - type: object
54 description: >-
55 A batch of queries to run in one round-trip to the search
56 engine.
57 required:
58 - queries
59 properties:
60 queries:
61 type: array
62 description: >-
63 The queries to run, in the order their results are returned
64 in.
65 items:
66 allOf:
67 - type: object
68 description: >-
69 A single query to run against one of the store's
70 search indexes.
71 required:
72 - entity
73 properties:
74 entity:
75 type: string
76 title: entity
77 description: >-
78 The name of the index to query, which defaults to
79 the index whose name
80
81 equals the entity.
82 fields:
83 type: array
84 description: >-
85 The dotted paths of the fields the search engine
86 returns. Only fields stored in the search index
87 can be passed here.
88 items:
89 type: string
90 title: fields
91 description: A field's dotted path.
92 filters:
93 allOf:
94 - type: object
95 description: >-
96 The filters to apply, including the free-text
97 query as `q`.
98 properties:
99 $and:
100 type: array
101 description: >-
102 Join query parameters with an AND
103 condition. Each object's content is the
104 same type as the expected query
105 parameters.
106 items:
107 type: object
108 title: $and
109 $or:
110 type: array
111 description: >-
112 Join query parameters with an OR
113 condition. Each object's content is the
114 same type as the expected query
115 parameters.
116 items:
117 type: object
118 title: $or
119 $not:
120 allOf:
121 - type: object
122 description: >-
123 Filter by values not matching the
124 conditions in this parameter.
125 properties:
126 $and:
127 type: array
128 description: >-
129 Join query parameters with an AND
130 condition. Each object's content is the
131 same type as the expected query
132 parameters.
133 items:
134 type: object
135 title: $and
136 $or:
137 type: array
138 description: >-
139 Join query parameters with an OR
140 condition. Each object's content is the
141 same type as the expected query
142 parameters.
143 items:
144 type: object
145 title: $or
146 $not:
147 allOf:
148 - type: object
149 description: >-
150 Filter by values not matching the
151 conditions in this parameter.
152 properties:
153 $and:
154 type: array
155 description: >-
156 Join query parameters with an AND
157 condition. Each object's content is the
158 same type as the expected query
159 parameters.
160 items:
161 type: object
162 title: $and
163 $or:
164 type: array
165 description: >-
166 Join query parameters with an OR
167 condition. Each object's content is the
168 same type as the expected query
169 parameters.
170 items:
171 type: object
172 title: $or
173 $not:
174 allOf:
175 - type: object
176 description: >-
177 Filter by values not matching the
178 conditions in this parameter.
179 properties:
180 $and:
181 type: array
182 description: >-
183 Join query parameters with an AND
184 condition. Each object's content is the
185 same type as the expected query
186 parameters.
187 items:
188 type: object
189 title: $and
190 $or:
191 type: array
192 description: >-
193 Join query parameters with an OR
194 condition. Each object's content is the
195 same type as the expected query
196 parameters.
197 items:
198 type: object
199 title: $or
200 $not:
201 allOf:
202 - type: object
203 description: >-
204 Filter by values not matching the
205 conditions in this parameter.
206 - type: object
207 description: >-
208 Filter by values not matching the
209 conditions in this parameter.
210 q:
211 type: string
212 title: q
213 description: >-
214 The free-text query to match the
215 documents against.
216 - type: object
217 description: >-
218 Filter by values not matching the
219 conditions in this parameter.
220 q:
221 type: string
222 title: q
223 description: >-
224 The free-text query to match the
225 documents against.
226 - type: object
227 description: >-
228 Filter by values not matching the
229 conditions in this parameter.
230 q:
231 type: string
232 title: q
233 description: >-
234 The free-text query to match the
235 documents against.
236 - type: object
237 description: >-
238 Filter by values not matching the
239 conditions in this parameter.
240 q:
241 type: string
242 title: q
243 description: >-
244 The free-text query to match the documents
245 against.
246 - type: object
247 description: >-
248 The filters to apply, including the free-text
249 query as `q`.
250 pagination:
251 $ref: ../components/schemas/SearchPagination.yaml
252 - type: object
253 description: >-
254 The options changing how the query is matched, scored,
255 and aggregated.
256 properties:
257 search_options:
258 $ref: ../components/schemas/SearchOptions.yaml
259 - allOf:
260 - type: object
261 description: >-
262 A single query to run against one of the store's search
263 indexes.
264 required:
265 - entity
266 properties:
267 entity:
268 type: string
269 title: entity
270 description: >-
271 The name of the index to query, which defaults to the
272 index whose name
273
274 equals the entity.
275 fields:
276 type: array
277 description: >-
278 The dotted paths of the fields the search engine
279 returns. Only fields stored in the search index can be
280 passed here.
281 items:
282 type: string
283 title: fields
284 description: A field's dotted path.
285 filters:
286 allOf:
287 - type: object
288 description: >-
289 The filters to apply, including the free-text query
290 as `q`.
291 properties:
292 $and:
293 type: array
294 description: >-
295 Join query parameters with an AND condition.
296 Each object's content is the same type as the
297 expected query parameters.
298 items:
299 type: object
300 title: $and
301 $or:
302 type: array
303 description: >-
304 Join query parameters with an OR condition. Each
305 object's content is the same type as the
306 expected query parameters.
307 items:
308 type: object
309 title: $or
310 $not:
311 allOf:
312 - type: object
313 description: >-
314 Filter by values not matching the conditions
315 in this parameter.
316 properties:
317 $and:
318 type: array
319 description: >-
320 Join query parameters with an AND
321 condition. Each object's content is the
322 same type as the expected query
323 parameters.
324 items:
325 type: object
326 title: $and
327 $or:
328 type: array
329 description: >-
330 Join query parameters with an OR
331 condition. Each object's content is the
332 same type as the expected query
333 parameters.
334 items:
335 type: object
336 title: $or
337 $not:
338 allOf:
339 - type: object
340 description: >-
341 Filter by values not matching the
342 conditions in this parameter.
343 properties:
344 $and:
345 type: array
346 description: >-
347 Join query parameters with an AND
348 condition. Each object's content is the
349 same type as the expected query
350 parameters.
351 items:
352 type: object
353 title: $and
354 $or:
355 type: array
356 description: >-
357 Join query parameters with an OR
358 condition. Each object's content is the
359 same type as the expected query
360 parameters.
361 items:
362 type: object
363 title: $or
364 $not:
365 allOf:
366 - type: object
367 description: >-
368 Filter by values not matching the
369 conditions in this parameter.
370 properties:
371 $and:
372 type: array
373 description: >-
374 Join query parameters with an AND
375 condition. Each object's content is the
376 same type as the expected query
377 parameters.
378 items:
379 type: object
380 title: $and
381 $or:
382 type: array
383 description: >-
384 Join query parameters with an OR
385 condition. Each object's content is the
386 same type as the expected query
387 parameters.
388 items:
389 type: object
390 title: $or
391 $not:
392 allOf:
393 - type: object
394 description: >-
395 Filter by values not matching the
396 conditions in this parameter.
397 properties:
398 $and:
399 type: array
400 description: >-
401 Join query parameters with an AND
402 condition. Each object's content is the
403 same type as the expected query
404 parameters.
405 items:
406 type: object
407 title: $and
408 $or:
409 type: array
410 description: >-
411 Join query parameters with an OR
412 condition. Each object's content is the
413 same type as the expected query
414 parameters.
415 items:
416 type: object
417 title: $or
418 $not:
419 allOf:
420 - type: object
421 description: >-
422 Filter by values not matching the
423 conditions in this parameter.
424 - type: object
425 description: >-
426 Filter by values not matching the
427 conditions in this parameter.
428 q:
429 type: string
430 title: q
431 description: >-
432 The free-text query to match the
433 documents against.
434 - type: object
435 description: >-
436 Filter by values not matching the
437 conditions in this parameter.
438 q:
439 type: string
440 title: q
441 description: >-
442 The free-text query to match the
443 documents against.
444 - type: object
445 description: >-
446 Filter by values not matching the
447 conditions in this parameter.
448 q:
449 type: string
450 title: q
451 description: >-
452 The free-text query to match the
453 documents against.
454 - type: object
455 description: >-
456 Filter by values not matching the
457 conditions in this parameter.
458 q:
459 type: string
460 title: q
461 description: >-
462 The free-text query to match the
463 documents against.
464 - type: object
465 description: >-
466 Filter by values not matching the conditions
467 in this parameter.
468 q:
469 type: string
470 title: q
471 description: >-
472 The free-text query to match the documents
473 against.
474 - type: object
475 description: >-
476 The filters to apply, including the free-text query
477 as `q`.
478 pagination:
479 $ref: ../components/schemas/SearchPagination.yaml
480 - type: object
481 description: >-
482 The options changing how the query is matched, scored, and
483 aggregated.
484 properties:
485 search_options:
486 $ref: ../components/schemas/SearchOptions.yaml
487 x-codeSamples:
488 - lang: Shell
489 label: cURL
490 source:
491 $ref: ../code_samples/Shell/store_search/post.sh
492 tags:
493 - Search
494 responses:
495 '200':
496 description: OK
497 content:
498 application/json:
499 schema:
500 type: object
501 description: The results of the search queries.
502 required:
503 - results
504 properties:
505 results:
506 type: array
507 description: >-
508 The results of the posted queries, in the order they were sent
509 in.
510 items:
511 type: object
512 description: The results of one of the posted queries.
513 required:
514 - hits
515 - metadata
516 properties:
517 hits:
518 type: array
519 description: >-
520 The documents matching the query, ordered by the query's
521 sort or by relevance.
522 items:
523 type: object
524 description: A document matching the query.
525 required:
526 - id
527 - document
528 properties:
529 id:
530 type: string
531 title: id
532 description: >-
533 The value of the index's primary key for this
534 document. `query.search` uses
535
536 it to hydrate the rest of the entity through
537 `query.graph`.
538 score:
539 type: number
540 title: score
541 description: >-
542 The hit's relevance score. It's only returned when
543 the query enables `include_score`.
544 document:
545 type: object
546 description: >-
547 The retrievable fields the search engine returned
548 for this document.
549 highlights:
550 type: object
551 description: >-
552 The highlighted fragments of the matched fields,
553 keyed by each field's dotted path. They're only
554 returned when the query enables `highlight`.
555 facets:
556 type: object
557 description: >-
558 The computed facets, keyed by the field they were
559 requested on.
560 metadata:
561 $ref: ../components/schemas/SearchResultMetadata.yaml
562 provider_metadata:
563 type: object
564 description: >-
565 Extra details the search provider returned, passed
566 through as-is.
567 '400':
568 $ref: ../components/responses/400_error.yaml
569 '401':
570 $ref: ../components/responses/unauthorized.yaml
571 '404':
572 $ref: ../components/responses/not_found_error.yaml
573 '409':
574 $ref: ../components/responses/invalid_state_error.yaml
575 '422':
576 $ref: ../components/responses/invalid_request_error.yaml
577 '500':
578 $ref: ../components/responses/500_error.yaml
579 x-since: 2.21.1