> ## Documentation Index
> Fetch the complete documentation index at: https://www.meilisearch.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Pin one result for a query

> Pin a single document to a fixed position whenever a search query contains a specific substring.

Pinning one document for a known query is the most common search rule pattern. Use it when you know exactly which document users should see when they search for a particular term, such as pinning your "Billing workspace overview" article for "invoice" queries, or a password-reset guide for "password" queries. The pinned document appears on top of the organic results without changing how the rest of the results are ranked.

<Warning>
  Search rules are experimental. Enable the `dynamicSearchRules` flag with `PATCH /experimental-features` before creating rules. See [Getting started](/docs/capabilities/search_rules/getting_started#enable-the-experimental-flag).
</Warning>

## Example scenario

You run a help center on a `support` index. Users often type "invoice" when they are looking for the "Billing workspace overview" article (document `id: "billing-workspace-overview"`). Currently, that article ranks third organically. You want it to appear first whenever the word "invoice" appears in the query.

A single search rule with one condition and one pin action covers this.

## Set up from the Meilisearch Cloud dashboard

Open your project in the [Meilisearch Cloud dashboard](https://cloud.meilisearch.com) and select the **Search rules** tab.

### 1. Create a new rule

Click **New rule** in the top-right corner.

<img src="https://mintcdn.com/meilisearch-6b28dec2/UuxowY4mE7FIY7Tq/assets/images/cloud-search-rules/02-create-first-rule.png?fit=max&auto=format&n=UuxowY4mE7FIY7Tq&q=85&s=efe99e972181af565d8526fb254aed53" alt="Search rules tab with the &#x22;New rule&#x22; button in the top-right corner" width="3200" height="1954" data-path="assets/images/cloud-search-rules/02-create-first-rule.png" />

### 2. Fill in the rule's general information

Give the rule a descriptive **Rule ID**, for example `invoice-help`. This value becomes the rule's `uid` in the API and cannot be changed later without recreating the rule. Add a short **Description** so your team knows what the rule does. Leave **Rank** at `0` unless you already have a competing rule, and keep the **Active** toggle on so the rule applies at search time.

<img src="https://mintcdn.com/meilisearch-6b28dec2/wJuKwW0_RUzzq03L/assets/images/cloud-search-rules/03-manage-rule.png?fit=max&auto=format&n=wJuKwW0_RUzzq03L&q=85&s=19c2b743bfd03fd3ef4391f8940c9652" alt="Rule editor showing Rule ID, Description, and Rank fields with the Active toggle on" width="2564" height="1296" data-path="assets/images/cloud-search-rules/03-manage-rule.png" />

### 3. Add a query condition

In the **Conditions** block, click the combo box below `Query`, then pick `Contains all words`, and enter `invoice` in the nearby field.

<img src="https://mintcdn.com/meilisearch-6b28dec2/wJuKwW0_RUzzq03L/assets/images/cloud-search-rules/04-add-condition.png?fit=max&auto=format&n=wJuKwW0_RUzzq03L&q=85&s=b595e5bca5d6d278b94e690eca69f4f3" alt="Add condition dialog with &#x22;Query contains&#x22; type and a substring input" width="2564" height="1296" data-path="assets/images/cloud-search-rules/04-add-condition.png" />

### 4. Pin the target document

In the **Actions** block, click **Add pin**. In the dialog:

* Set **Index** to the index that holds the document, for example `support`
* Pick the document under **Document** (here, `billing-workspace-overview`)
* Set **Position** to `0` so the document lands in the first result slot

Click **Add pin**.

<img src="https://mintcdn.com/meilisearch-6b28dec2/wJuKwW0_RUzzq03L/assets/images/cloud-search-rules/05-add-pin.png?fit=max&auto=format&n=wJuKwW0_RUzzq03L&q=85&s=9adce48cc6236f50a599558299f31fd2" alt="Add pin dialog with index, document, and position configured" width="2564" height="1296" data-path="assets/images/cloud-search-rules/05-add-pin.png" />

### 5. Save the rule

Back on the rule editor, confirm that the Conditions and Actions sections show the entries you just created. Click **Create rule** in the bottom-right corner.

The rule now appears in the Search rules list. You can edit it, deactivate it, or delete it from this view later.

<img src="https://mintcdn.com/meilisearch-6b28dec2/wJuKwW0_RUzzq03L/assets/images/cloud-search-rules/06-rules-list.png?fit=max&auto=format&n=wJuKwW0_RUzzq03L&q=85&s=b2a435e9d4d999d67a229c60a6f66d35" alt="Search rules list showing the new invoice-help rule" width="2564" height="1296" data-path="assets/images/cloud-search-rules/06-rules-list.png" />

## Set up from the API

Send a `PATCH /dynamic-search-rules/invoice-help` with the following body:

```json theme={null}
{
  "description": "Promote billing help for invoice searches",
  "active": true,
  "conditions": {
    "query": {
      "words": "invoice"
    }
  },
  "actions": [
    {
      "selector": { "indexUid": "support", "id": "billing-workspace-overview" },
      "action": { "type": "pin", "position": 0 }
    }
  ]
}
```

* `uid` comes from the URL (`invoice-help`), not from the body.
* `position: 0` targets the first result slot.
* `indexUid` in the selector scopes the pin to the document living in the `support` index. If you omit it, Meilisearch treats the pin as a cross-index reference.
* The route returns a `202 ACCEPTED` and the task that needs processing for the rule to be active.

## How Meilisearch evaluates the rule

At search time, Meilisearch:

1. Matches the search query against every active rule
2. For each matching rule, verifies that the pinned document exists and passes the current search filters
3. Inserts the surviving pinned document at the requested position
4. Removes duplicates from the final result set

If the pinned document is missing from the index or filtered out by the search request, Meilisearch drops the pin instead of forcing the document into the response. Organic results fill the rest of the positions.

## Next steps

<CardGroup cols={2}>
  <Card title="Pin several results in a fixed order" href="/docs/capabilities/search_rules/how_to/pin_multiple_results">
    Add multiple pin actions to the same rule
  </Card>

  <Card title="Schedule a promotion" href="/docs/capabilities/search_rules/how_to/schedule_promotion">
    Combine a query condition with a time window
  </Card>

  <Card title="Pinning behavior" href="/docs/capabilities/search_rules/advanced/pinning_behavior">
    Learn how pins interact with ranking, filters, and precedence
  </Card>

  <Card title="Pause a rule" href="/docs/capabilities/search_rules/how_to/pause_a_rule">
    Temporarily disable a rule without deleting it
  </Card>

  <Card title="API reference" href="/docs/reference/api/search-rules/create-or-update-a-search-rule">
    Full request and response shapes
  </Card>
</CardGroup>
