Sep 20, 2024
Create or replace a rule
If a rule with the specified object ID doesn’t exist, it’s created. Otherwise, the existing rule is replaced.
To create or update more than one rule, use the batch
operation.
Usage
Required ACL:
editSettings
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using Algolia.Search.Clients;
using Algolia.Search.Http;
using Algolia.Search.Models.Search;
var client = new SearchClient(new SearchConfig("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY"));
var response = await client.SaveRuleAsync(
"ALGOLIA_INDEX_NAME",
"id1",
new Rule
{
ObjectID = "id1",
Conditions = new List<Condition>
{
new Condition { Pattern = "apple", Anchoring = Enum.Parse<Anchoring>("Contains") },
},
Consequence = new Consequence
{
Params = new ConsequenceParams { Filters = "brand:xiaomi" },
},
}
);
Did you find this page helpful?