Skip to main content
You can use rules to detect a specific word and modify a parameter because of this word.

Limit the search to only a subset of attributes

A good example of altering a query is with an online document library that allows keyword searches inside documents. If a user types in the word “article ref21”, they’re probably looking for an article whose title or ID contains “ref21”._

Rule

If query = “article ref21” then remove article and search for an article whose title or ID contains ‘ref21’

API

To run the code examples on this page, install the latest API client.
var response = await client.SaveRuleAsync(
  "INDEX_NAME",
  "article-rule",
  new Rule
  {
    ObjectID = "article-rule",
    Conditions = new List<Condition>
    {
      new Condition { Pattern = "article", Anchoring = Enum.Parse<Anchoring>("StartsWith") },
    },
    Consequence = new Consequence
    {
      Params = new ConsequenceParams
      {
        Query = new ConsequenceQuery(
          new ConsequenceQueryObject
          {
            Edits = new List<Edit>
            {
              new Edit { Type = Enum.Parse<EditType>("Remove"), Delete = "article" },
            },
          }
        ),
        RestrictSearchableAttributes = new List<string> { "title", "book_id" },
      },
    },
  }
);

Using the dashboard

You can also add your rules in your Algolia dashboard.
  1. Select the Search product icon on your dashboard and then select your .
  2. Select the Rules section from the left sidebar menu in the Algolia dashboard.
  3. Under the heading Rules, select the index you are adding a Rule to.
  4. Click New rule.
  5. Select Create your first rule or New rule. In the drop-down menu, click Manual Editor.
  6. In the Condition(s) section, keep Query toggled on, select Contains in the drop-down menu, and enter “article” in the input field.
  7. In the Consequence(s) section:
    • Click the Add consequence button and select Add Query Parameter.
    • In the input field that appears, enter the JSON search parameter you want to add. For example, { "restrictSearchableAttributes": ["title","id"] }.
    • Click the Add consequence button again and select Remove Word.
    • Type or select “article” in the input field.
  8. Save your changes.
Last modified on March 16, 2026