Skip to content

Meilisearch integration

⭐ Community Toolkit Meilisearch logo

Meilisearch is a fast, open-source search engine that makes search and discovery easy. The Aspire Meilisearch integration enables you to connect to existing Meilisearch instances or create new instances from Aspire using the docker.io/getmeili/meilisearch container image.

To run the Meilisearch container, install the 📦 CommunityToolkit.Aspire.Hosting.Meilisearch NuGet package in the AppHost project.

Aspire CLI — Add CommunityToolkit.Aspire.Hosting.Meilisearch package
aspire add communitytoolkit-meilisearch

The Aspire CLI is interactive, be sure to select the appropriate search result when prompted:

Aspire CLI — Example output prompt
Select an integration to add:
> communitytoolkit-meilisearch (CommunityToolkit.Aspire.Hosting.Meilisearch)
> Other results listed as selectable options...

In the AppHost project, register and consume the Meilisearch integration using the AddMeilisearch extension method to add the Meilisearch container to the application builder.

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var meilisearch = builder.AddMeilisearch("meilisearch");
builder.AddProject<Projects.ExampleProject>()
.WithReference(meilisearch);
// After adding all resources, run the app...

The Meilisearch resource includes a randomly generated master key when one wasn’t provided.

To add a data volume to the Meilisearch resource, call the WithDataVolume method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var meilisearch = builder.AddMeilisearch("meilisearch")
.WithDataVolume();
builder.AddProject<Projects.ExampleProject>()
.WithReference(meilisearch);
// After adding all resources, run the app...

The data volume is used to persist the Meilisearch data outside the lifecycle of its container. The data volume is mounted at the /meili_data path in the Meilisearch container.

Add Meilisearch resource with data bind mount

Section titled “Add Meilisearch resource with data bind mount”

To add a data bind mount to the Meilisearch resource, call the WithDataBindMount method:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var meilisearch = builder.AddMeilisearch("meilisearch")
.WithDataBindMount(source: @"C:\Meilisearch\Data");
builder.AddProject<Projects.ExampleProject>()
.WithReference(meilisearch);
// After adding all resources, run the app...

Data bind mounts rely on the host machine’s filesystem to persist the Meilisearch data across container restarts.

Add Meilisearch resource with master key parameter

Section titled “Add Meilisearch resource with master key parameter”

When you want to explicitly provide the master key used by the container image, you can provide these credentials as parameters:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var masterkey = builder.AddParameter("masterkey", secret: true);
var meilisearch = builder.AddMeilisearch("meilisearch", masterkey);
builder.AddProject<Projects.ExampleProject>()
.WithReference(meilisearch);
// After adding all resources, run the app...

To get started with the Aspire Meilisearch client integration, install the 📦 CommunityToolkit.Aspire.Meilisearch NuGet package in the client-consuming project.

.NET CLI — Add CommunityToolkit.Aspire.Meilisearch package
dotnet add package CommunityToolkit.Aspire.Meilisearch

In the Program.cs file of your client-consuming project, call the AddMeilisearchClient extension method to register a MeilisearchClient for use via the dependency injection container. The method takes a connection name parameter.

builder.AddMeilisearchClient(connectionName: "meilisearch");

You can then retrieve the MeilisearchClient instance using dependency injection:

public class ExampleService(MeilisearchClient client)
{
// Use client...
}

There might be situations where you want to register multiple MeilisearchClient instances with different connection names. To register keyed Meilisearch clients, call the AddKeyedMeilisearchClient method:

builder.AddKeyedMeilisearchClient(name: "products");
builder.AddKeyedMeilisearchClient(name: "orders");

Then you can retrieve the MeilisearchClient instances using dependency injection:

public class ExampleService(
[FromKeyedServices("products")] MeilisearchClient productsClient,
[FromKeyedServices("orders")] MeilisearchClient ordersClient)
{
// Use clients...
}

The Aspire Meilisearch client integration provides multiple options to configure the server connection.

When using a connection string from the ConnectionStrings configuration section, provide the name of the connection string:

builder.AddMeilisearchClient("meilisearch");

Then the connection string will be retrieved from the ConnectionStrings configuration section:

{
"ConnectionStrings": {
"meilisearch": "Endpoint=http://localhost:19530/;MasterKey=123456!@#$%"
}
}

The Aspire Meilisearch Client integration supports configuration. It loads the settings from configuration using the Aspire:Meilisearch:Client key:

{
"Aspire": {
"Meilisearch": {
"Client": {
"Endpoint": "http://localhost:19530/",
"MasterKey": "123456!@#$%"
}
}
}
}

The Aspire Meilisearch integration uses the configured client to perform a health check.

FAQCollaborateCommunityDiscussWatch