Skip to content
Docs Try Aspire
Docs Try

Set up Meilisearch in the AppHost

⭐ Community Toolkit Meilisearch logo

This article is the reference for the Aspire Meilisearch Hosting integration. It enumerates the AppHost APIs that you use to model a Meilisearch resource in your AppHost project.

If you’re new to the Meilisearch integration, start with the Get started with Meilisearch integrations guide. For how consuming apps read the connection information this page exposes, see Connect to Meilisearch.

To start building an Aspire app that uses Meilisearch, install the 📦 CommunityToolkit.Aspire.Hosting.Meilisearch NuGet package:

Terminal
aspire add CommunityToolkit.Aspire.Hosting.Meilisearch

Learn more about aspire add in the command reference.

Or, choose a manual installation approach:

C# — AppHost.cs
#:package CommunityToolkit.Aspire.Hosting.Meilisearch@*
XML — AppHost.csproj
<PackageReference Include="CommunityToolkit.Aspire.Hosting.Meilisearch" Version="*" />

Once you’ve installed the hosting integration in your AppHost project, you can add a Meilisearch resource as shown in the following example:

C# — AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var meilisearch = builder.AddMeilisearch("meilisearch");
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(meilisearch);
// After adding all resources, run the app...
  1. When Aspire adds a container image to the AppHost, as shown in the preceding example with the docker.io/getmeili/meilisearch image, it creates a new Meilisearch instance on your local machine.

  2. The Meilisearch resource is configured with a randomly generated master key by default. To set an explicit master key, see Add Meilisearch resource with master key parameter.

  3. The WithReference call configures a connection in the consuming project named after the referenced Meilisearch resource, such as meilisearch in the preceding example.

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();
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(meilisearch);
// After adding all resources, run the app...

The data volume is used to persist Meilisearch data outside the lifecycle of its container. The data volume is mounted at the /meili_data path in the Meilisearch container. When a name parameter isn’t provided, the name is generated at random. For more information on data volumes and details on why they’re preferred over bind mounts, see Docker docs: Volumes.

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");
var exampleProject = builder.AddProject<Projects.ExampleProject>("apiservice")
.WithReference(meilisearch);
// After adding all resources, run the app...

Data bind mounts rely on the host machine’s filesystem to persist Meilisearch data across container restarts. The data bind mount is mounted at C:\Meilisearch\Data on Windows (or the equivalent path on Unix) on the host machine. For more information on data bind mounts, see Docker docs: Bind mounts.

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 it as a parameter:

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

When no masterKey parameter is provided, Aspire generates a strong master key automatically.

For the full reference of Meilisearch connection properties — and how consuming apps in C#, TypeScript, Python, and Go read them — see Connect to Meilisearch.

The Meilisearch hosting integration automatically adds a health check for the Meilisearch resource. The health check verifies that the Meilisearch instance is running and that a connection can be established to it.