/multi-search route allows you to perform multiple search queries on one or more indexes by bundling them into a single HTTP request. Multi-search is also known as federated search.
Perform a multi-search
Bundle multiple search queries in a single API request. Use this endpoint to search through multiple indexes at once.POST
/multi-search
Body
federation
Use federation to receive a single list with all search results from all specified queries, in descending ranking score order. This is called federated search.
federation may optionally contain the following parameters:
If
federation is missing or null, Meilisearch returns a list of multiple search result objects, with each item from the list corresponding to a search query in the request.
facetsByIndex
facetsByIndex must be an object. Its keys must correspond to indexes in your Meilisearch project. Each key must be associated with an array of attributes in the filterable attributes list of that index:
facetsByIndex, multi-search responses include an extra facetsByIndex field. The response’s facetsByIndex is an object with one field for each queried index:
mergeFacets
mergeFacets must be an object and may contain the following fields:
maxValuesPerFacet: must be an integer. When specified, indicates the maximum number of returned values for a single facet. Defaults to the value assigned to themaxValuesPerFacetindex setting
facetsByIndex and mergeFacets are present and not null, facet information included in multi-search responses is merged across all queried indexes. Instead of facetsByIndex, the response includes two extra fields: facetDistribution and facetStats:
Merge algorithm for federated searches
Federated search’s merged results are returned in decreasing ranking score. To obtain the final list of results, Meilisearch compares with the following procedure:- Detailed ranking scores are normalized in the following way for both hits:
- Consecutive relevancy scores (related to the rules
words,typo,attribute,exactnessorvector) are grouped in a single score for each hit sortandgeosortscore details remain unchanged
- Consecutive relevancy scores (related to the rules
- Normalized detailed ranking scores are compared lexicographically for both hits:
- If both hits have a relevancy score, then the bigger score wins. If it is a tie, move to next step
- If one result has a relevancy score or a (geo)sort score, Meilisearch picks it
- If both results have a sort or geosort score in the same sorting direction, then Meilisearch compares the values according to the common sort direction. The result with the value that must come first according to the common sort direction wins. If it is a tie, go to the next step
- Compare the global ranking scores of both hits to determine which comes first, ignoring any sorting or geosorting
- In the case of a perfect tie, documents from the query with the lowest rank in the
queriesarray are preferred.
Meilisearch considers two documents the same if:
- They come from the same index
- And their primary key is the same
queries
queries must be an array of objects. Each object may contain the following search parameters:
Unless otherwise noted, search parameters for multi-search queries function exactly like search parameters for the
/search endpoint.
limit, offset, hitsPerPage and page
These options are not compatible with federated searches.
federationOptions
federationOptions must be an object. It accepts the following parameters:
weight: serves as a multiplicative factor to ranking scores of search results in this specific query. If <1.0, the hits from this query are less likely to appear in the final results list. If >1.0, the hits from this query are more likely to appear in the final results list. Must be a positive floating-point number. Defaults to1.0remoteexperimental: indicates the remote instance where Meilisearch will perform the query. Must be a string corresponding to a remote object. Defaults tonull
Response
The response to/multi-search queries may take different shapes depending on the type of query you’re making.
Non-federated multi-search requests
Each search result object is composed of the following fields:
Federated multi-search requests
Federated search requests return a single object and the following fields:
Each result in the
hits array contains an additional _federation field with the following fields: