Create or update rules

Create or update multiple rules.

If a rule with the specified object ID doesn’t exist, Algolia creates a new one. Otherwise, existing rules are replaced.

Usage

Required ACL: editSettings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Algolia.Search.Clients;
using Algolia.Search.Models.Search;

var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));

var response = await client.SaveRulesAsync(
  "ALGOLIA_INDEX_NAME",
  new List<Rule>
  {
    new Rule
    {
      ObjectID = "a-rule-id",
      Conditions = new List<Condition>
      {
        new Condition { Pattern = "smartphone", Anchoring = Enum.Parse<Anchoring>("Contains") },
      },
    },
    new Rule
    {
      ObjectID = "a-second-rule-id",
      Conditions = new List<Condition>
      {
        new Condition { Pattern = "apple", Anchoring = Enum.Parse<Anchoring>("Contains") },
      },
    },
  },
  false,
  true
);
Did you find this page helpful?
C# API clients v7