Skip to content

Commit 67eff7e

Browse files
add federated search guide
1 parent 6693ea7 commit 67eff7e

File tree

5 files changed

+195
-0
lines changed

5 files changed

+195
-0
lines changed

assets/datasets/crm-chats.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[
2+
{
3+
"id": 0,
4+
"client_name": "Natasha Nguyen",
5+
"message": "My email is [email protected]",
6+
"time": 1727349362
7+
},
8+
{
9+
"id": 1,
10+
"client_name": "Riccardo Rotondo",
11+
"message": "No, I changed my email, it's no longer [email protected], the one you see on my profile is the right one",
12+
"time": 1726344418
13+
}
14+
]

assets/datasets/crm-profiles.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
[
2+
{
3+
"id": 0,
4+
"name": "Natasha Nguyen",
5+
"email": "[email protected]"
6+
},
7+
{
8+
"id": 1,
9+
"name": "Riccardo Rotondo",
10+
"email": "[email protected]"
11+
}
12+
]

assets/datasets/crm-tickets.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[
2+
{
3+
"id": 0,
4+
"time": 1727349362,
5+
"client_name": "Natasha Nguyen",
6+
"type": "complaint",
7+
"title": "I'm not receiving any emails"
8+
},
9+
{
10+
"id": 1,
11+
"time": 1701448312,
12+
"client_name": "Riccardo Rotondo",
13+
"type": "support",
14+
"title": "Please remove my email from your mailing list"
15+
}
16+
]
17+

config/sidebar-learn.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,17 @@
253253
}
254254
]
255255
},
256+
{
257+
"title": "Multi-search",
258+
"slug": "multi_search",
259+
"routes": [
260+
{
261+
"source": "learn/multi_search/federated_search_guide.mdx",
262+
"label": "Federated search guide",
263+
"slug": "federated_search_guide"
264+
}
265+
]
266+
},
256267
{
257268
"title": "Update and migration",
258269
"slug": "update_and_migration",
Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
---
2+
title: Federated search guide — Meilisearch API reference
3+
description:
4+
---
5+
6+
# Federated search guide
7+
8+
A federated search is a multi-index search that returns results across multiple indexes in a single list.
9+
10+
In this guide you will see how to create separate indexes containing different types of data from a CRM application. You will then perform a query searching all these indexes at the same time to obtain a single list of results.
11+
12+
## Requirements
13+
14+
- A running Meilisearch project
15+
- A command-line console
16+
17+
## Create three indexes
18+
19+
Download the following datasets: <a href="/assets/datasets/crm-chats.json">`crm-chats.json`</a>, <a href="/assets/datasets/crm-profiles.json">`crm-profiles.json`</a>, and <a href="/assets/datasets/crm-tickets.json">`crm-tickets.json`</a> containing customer interaction data. Add them to Meilisearch, creating three separate indexes, `profiles`, `chats`, and `tickets`:
20+
21+
```sh
22+
curl -X POST 'http://localhost:7700/indexes/profiles' -H 'Content-Type: application/json' --data-binary @crm-profiles.json &&
23+
curl -X POST 'http://localhost:7700/indexes/chats' -H 'Content-Type: application/json' --data-binary @crm-chats.json &&
24+
curl -X POST 'http://localhost:7700/indexes/tickets' -H 'Content-Type: application/json' --data-binary @crm-tickets.json
25+
```
26+
27+
Use the tasks endpoint to check the indexing status. Once Meilisearch successfully indexed all three datasets, you are ready to perform a federated search.
28+
29+
## Perform a federated search
30+
31+
When you are looking for Natasha Nguyen's email address in your CRM application, you may not know whether you will find it in a chat log, among the existing customer profiles, or in a recent support ticket. In this situation, you can use federated search to search across all possible sources and receive a single list of results.
32+
33+
Use the `/multi-search` endpoint with the `federation` parameter to query the three indexes simultaneously:
34+
35+
```sh
36+
curl \
37+
-X POST 'http://localhost:7700/multi-search' \
38+
-H 'Content-Type: application/json' \
39+
--data-binary '{
40+
"federation": {},
41+
"queries": [
42+
{
43+
"indexUid": "chats",
44+
"q": "natasha"
45+
},
46+
{
47+
"indexUid": "profiles",
48+
"q": "natasha"
49+
},
50+
{
51+
"indexUid": "tickets",
52+
"q": "natasha"
53+
}
54+
]
55+
}'
56+
```
57+
58+
Meilisearch should respond with a single list of search results:
59+
60+
```json
61+
{
62+
"hits": [
63+
{
64+
"id": 0,
65+
"client_name": "Natasha Nguyen",
66+
"message": "My email is [email protected]",
67+
"time": 1727349362,
68+
"_federation": {
69+
"indexUid": "chats",
70+
"queriesPosition": 0
71+
}
72+
},
73+
74+
],
75+
"processingTimeMs": 0,
76+
"limit": 20,
77+
"offset": 0,
78+
"estimatedTotalHits": 3,
79+
"semanticHitCount": 0
80+
}
81+
```
82+
83+
## Promote results from an index
84+
85+
Since this is a CRM application, it is likely your users have profiles where they specified their preferred contact information. If you want to search for Riccardo Rotondo's official preferred email, you can boost documents in the `profiles` index.
86+
87+
Use the `weight` property of the `federation` parameter to boost results coming from a specific index:
88+
89+
```sh
90+
curl \
91+
-X POST 'http://localhost:7700/multi-search' \
92+
-H 'Content-Type: application/json' \
93+
--data-binary '{
94+
"federation": {},
95+
"queries": [
96+
{
97+
"indexUid": "chats",
98+
"q": "rotondo"
99+
},
100+
{
101+
"indexUid": "profiles",
102+
"q": "rotondo",
103+
"federationOptions": {
104+
"weight": 1.2
105+
}
106+
},
107+
{
108+
"indexUid": "tickets",
109+
"q": "rotondo"
110+
}
111+
]
112+
}'
113+
```
114+
115+
This query will result in `profile` results ranking higher than documents in other indexes:
116+
117+
```json
118+
{
119+
"hits": [
120+
{
121+
"id": 1,
122+
"name": "Riccardo Rotondo",
123+
"email": "[email protected]",
124+
"_federation": {
125+
"indexUid": "profiles",
126+
"queriesPosition": 1
127+
}
128+
},
129+
130+
],
131+
"processingTimeMs": 0,
132+
"limit": 20,
133+
"offset": 0,
134+
"estimatedTotalHits": 3,
135+
"semanticHitCount": 0
136+
}
137+
```
138+
139+
## Conclusion
140+
141+
You have created three indexes, then performed a federated multi-index search to receive all results in a single list. You then used `weight` to boost results from the index most likely to contain the information you wanted.

0 commit comments

Comments
 (0)