Meilisearch v1.1 introduces the /multi-search
endpoint. With this endpoint, users can now send multiple search queries on one or more indexes by bundling them into a single HTTP request. Essentially, the /multi-search
endpoint paves the way for federated search.
Multi-index search with Meilisearch
With 277 votes, federated search was one of the most requested features. We are glad to finally announce the first stage of the feature.
We have introduced a /multi-search
route that allows searching in multiple indexes with a single HTTP request. Suppose we have two indexes: movies
and actors
. Using the /multi-search
endpoint, we can search for the name of an actress and retrieve both her biography and movies in the search results.
Take, for instance, the following multi-search request:
curl \
-X POST 'http://localhost:7700/multi-search' \
-H 'Content-Type: application/json' \
--data-binary '{
"queries": [
{
"indexUid": "movies",
"q": "Kate Winslet",
"limit": 1
},
{
"indexUid": "actors",
"q": "Kate Winslet",
"limit": 1
}
]
}'
The response will include a set of search results for each index searched:
{
"results": [
{
"indexUid": "movies",
"hits": [
{
"title": "The Reader",
"overview": "The story of Michael Berg, a German lawyer who, as a teenager in the late 1950s, had an affair with an older woman, Hanna, who then disappeared only to resurface years later as one of the defendants in a war crimes trial stemming from her actions as a concentration camp guard late in the war. He alone realizes that Hanna is illiterate and may be concealing that fact at the expense of her freedom.",
"crew": [...],
"cast": [
...
{
"character": "Hanna Schmitz",
"name": "Kate Winslet",
"profile_path": "/e3tdop3WhseRnn8KwMVLAV25Ybv.jpg"
},
...
]
}
],
// other search results fields: processingTimeMs, limit, ...
},
{
"indexUid": "actors",
"hits": [
{
"name": "Kate Winslet",
"known_for": [
"Titanic",
"Eternal Sunshine of the Spotless Mind",
"The Reader"
],
"birthday": "1975-10-05",
"deathday": null,
"biography": "Kate Elizabeth Winslet (born 5 October 1975) is an English actress. Known for her work in independent films..."
}
],
// other search results fields: processingTimeMs, limit, ...
}
]
}
As you can see, in the results array, the indexes are sorted in the same order as in the query. The response contains the usual fields that a conventional search returns along with the index UIDs. Note that, we restricted the number of documents returned to just one using the limit
parameter in this example.
Multi-index search demo
Try it yourself!
This demo uses two datasets: movies and actors. Each dataset is stored in its own index, has its own settings, and, as you can see in the example above, its own schema.
Since the two indexes have different schemas, they have different searchable attributes. In the movies index, you can search for a movie by its title, characters, actors, producers, directors, or movie overview.
//movies index
searchableAttributes: [
'title',
'crew.name',
'cast.name',
'cast.character',
'overview',
]
The actors index allows you to search for actors by name, as well as the movies or shows they are most known for, and by keywords found in their biographies.
//actors index
searchableAttributes: ['name', 'known_for', 'biography']
The full list of settings, dataset, and code are all available on GitHub, so feel free to explore them on your own. Don't hesitate to play around with the settings to customize the behavior to your needs. If you have ideas for improving the demo, like adding facets, don't hesitate to submit a pull request. All contributions are welcome!
Conclusion
We are excited to deliver this first iteration of federated search, and we’ll be working hard to push toward aggregated search results. We couldn't have achieved this without the valuable feedback and insights provided by our developer community. Your feedback has been instrumental in helping us prioritize and shape the feature to meet your needs.
If you're interested in keeping up with our progress, we encourage you to check out our product roadmap, join our discussions on GitHub, or connect with us on Discord.
As always, we are committed to providing our users with the best possible search experience and appreciate your help in achieving this goal.