/network route, configuring the network object, and performing search across all shards.
Sharding is an Enterprise Edition feature. You are free to use it for evaluation purposes. Please reach out to us before using it in production.
Prerequisites
- Multiple Meilisearch projects (instances) running Meilisearch >=v1.35
Activate the /network endpoint
Meilisearch Cloud
If you are using Meilisearch Cloud, contact support to enable this feature in your projects.Self-hosting
Use the/experimental-features route to enable network:
Configuring the network object
If you are using Meilisearch Cloud, then you can skip this section. Self-hosted users must configure the network object. It consists of the following fields:remotes: defines a list with the required information to access each remote instanceself: specifies which of the configuredremotescorresponds to the current instanceleader: specifies which of the configuredremotesis the leader of the network. Setting this field will enable sharding.shards: defines a list of shards representing the various pieces of the index data to split between the remotes.
Setting up the list of remotes
Use the/network route to configure the remotes field of the network object. remotes should be an object containing one or more objects. Each one of the nested objects should consist of the name of each instance,
associated with its URL, an API key with search permission, and an API key with write permission:
Pick a leader instance
In a Meilisearch network, the leader will be responsible for:- Receiving any task that modifies the state of the Meilisearch instance: document additions, settings change, etc.
- Any task will be replicated to the remote instances of the network.
- If you send a task to a non-leader remote instance, the task will not be registered and a 400 BAD REQUEST HTTP error code will be emitted.
- Receiving network change requests.
- They will be propagated to the rest of the network.
Specify the name of the current instance
Since the network change payload must be sent to the leader, this is always the same as the leader:self locally instead of making a remote request.
Setting up the list of shards
Shards are a list of named entries, each specifying a list of remotes that should own that shard. The same shard can be owned by multiple remotes, and remotes can own multiple shards, allowing to fine-tune how data is sharded and replicated in the network.Adding or removing an instance or shard
Changing the topology of the network involves moving some documents from an instance to another. Meilisearch will rebalance documents automatically depending on the change in network topology, via aNetworkTopologyChange task on all remotes of the network.
Add documents
Send your documents to the designated leader. Documents will be replicated to the other instances. Each instance will index the documents they are responsible for and ignore the others.Updating index settings
Changing settings in a sharded database is not fundamentally different from changing settings on a single Meilisearch instance. If the update enables a feature, such as setting filterable attributes, wait until all changes have been processed before using thefilter search parameter in a query.
Likewise, if an update disables a feature, first remove it from your search requests, then update your settings.
Perform a search
When sharding is enabled, your search requests will happen over all instances of the network automatically. To disable this behavior and force the request to be executed solely locally, adduseNetwork: false to your search requests.