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.

This operation is subject to indexing rate limits.

Usage

Required ACL: editSettings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import com.algolia.api.SearchClient;
import com.algolia.model.search.*;

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

client.saveRules(
  "ALGOLIA_INDEX_NAME",
  Arrays.asList(
    new Rule()
      .setObjectID("a-rule-id")
      .setConditions(Arrays.asList(new Condition().setPattern("smartphone").setAnchoring(Anchoring.CONTAINS)))
      .setConsequence(new Consequence().setParams(new ConsequenceParams().setFilters("brand:apple"))),
    new Rule()
      .setObjectID("a-second-rule-id")
      .setConditions(Arrays.asList(new Condition().setPattern("apple").setAnchoring(Anchoring.CONTAINS)))
      .setConsequence(new Consequence().setParams(new ConsequenceParams().setFilters("brand:samsung")))
  ),
  false,
  true
);
Did you find this page helpful?
Java API clients v4