Meilisearch

Detailed information on the Meilisearch search component

Component format

To set up a Meilisearch search store, create a component of type search.meilisearch. See this guide on how to create and apply a search store configuration.

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: <NAME>
spec:
  type: search.meilisearch
  version: v1
  metadata:
  - name: host
    value: "http://localhost:7700"
  - name: apiKey
    value: "<API_KEY>"
  - name: timeout
    value: "10s"

Spec metadata fields

FieldRequiredDetailsExample
hostYThe Meilisearch host URL."http://localhost:7700"
apiKeyNThe Meilisearch API key. Required when the Meilisearch instance is protected with a master key. Defaults to ""."masterKey"
timeoutNThe HTTP client timeout for requests to Meilisearch, as a Go duration."10s"

Supported features

FeatureSupportedDetails
Full-text searchYtext queries use Meilisearch’s keyword search.
FilteringYFilters must only use attributes declared in filterableAttributes. $regex isn’t supported.
SortingYSort fields must be declared in sortableAttributes.
HighlightingYHighlighted fragments use <em> tags.
PaginationYContinuation tokens are offset based.
Native queriesYSee native queries.
Queued acknowledgementYWrites return INDEX_ACK_QUEUED when Meilisearch enqueues the task, so INDEXING_WAIT_TIMEOUT_ACTION_CONTINUE_ASYNC is supported.
Wait for completionYSee waiting for writes.

Index settings

Pass the following Meilisearch index settings as comma-separated values in the metadata of a create index request:

MetadataDetailsExample
filterableAttributesContent fields that filters can use. Meilisearch rejects filters on fields that aren’t declared here."category,price"
sortableAttributesContent fields that sorts can use. id is always added, because the component uses the document ID as a tie-breaker for stable pagination."price,publishedAt"
searchableAttributesContent fields that full-text queries search, in order of importance. When omitted, all fields are searchable."title,body"

The component also moves the sort ranking rule first, so that a query with sort returns hits in the requested order, with relevance breaking ties.

Settings are only applied when an index is created. Creating an index that already exists returns ALREADY_EXISTS and doesn’t change its settings.

Get index returns the following properties: primaryKey (always id), and filterableAttributes, sortableAttributes, and searchableAttributes when set.

Document mapping

  • The document id is the Meilisearch primary key. It must be 1 to 511 bytes of ASCII letters, digits, hyphens, and underscores.
  • The keys of the document content are stored as top-level Meilisearch attributes. id, daprMetadata, daprPayload, and keys starting with _ are reserved by the component and can’t be used in content.
  • The document metadata is stored under the reserved daprMetadata attribute and returned unchanged. A full-text query never searches it.
  • A document with an invalid id, or whose content uses a reserved key, is reported in failedItems with INVALID_ARGUMENT and isn’t sent to Meilisearch. The rest of the batch is still indexed.
  • Indexing documents into an index that doesn’t exist fails the request with NOT_FOUND, instead of letting Meilisearch create an index without the component’s settings.

Scores and total hits

  • Hit scores are Meilisearch’s ranking score, a value between 0 and 1 where higher is more relevant.
  • totalHits is Meilisearch’s estimated total number of hits, reported with TOTAL_HITS_RELATION_ESTIMATE. When the total reaches the index’s maxTotalHits pagination setting, it is reported with TOTAL_HITS_RELATION_LOWER_BOUND, and results past that limit can’t be paged to.
  • When topK isn’t set, the component returns up to 20 hits per page.

Native queries

The query.native field of a search request accepts the parameters of the Meilisearch search API, for example q, filter, matchingStrategy, or attributesToCrop. Pagination and sorting use the portable query fields, so a native query must not set offset, limit, page, hitsPerPage, or sort. A native filter is combined with the portable filter using a logical AND, so it can only narrow the results.

{
  "query": {
    "native": { "q": "dapr", "matchingStrategy": "all" },
    "topK": 10
  }
}

Waiting for writes

Meilisearch processes writes asynchronously as tasks. With INDEXING_MODE_WAIT_FOR_COMPLETION, the component waits for the task to finish by polling the Meilisearch task API with exponential backoff.

When the experimental Meilisearch tasksStreamingRoute feature is enabled and the API key has the tasks.get permission, the component instead shares a single task-change stream for all waiting writes. If the route reports that it is unavailable, the component falls back to polling. The choice is transparent to your application.

A Meilisearch task is atomic: if the task fails, none of the documents in it are indexed, and a request that waits for completion fails with the task’s error. The component therefore checks the documents that Meilisearch would reject before it sends the task, and reports them in failedItems, as described in document mapping.

Setup Meilisearch

Run Meilisearch locally with Docker:

docker run -d --name meilisearch -p 7700:7700 \
  -e MEILI_MASTER_KEY=masterKey \
  getmeili/meilisearch:v1.43

Set host to http://localhost:7700 and apiKey to masterKey.

For other installation options, see the Meilisearch installation guide.

Create a project in Meilisearch Cloud, then set host to the project URL and apiKey to an API key with the permissions your application needs.