Jun 23, 2025
Create or update a batch of Recommend Rules
Create or update a batch of Recommend Rules
Each Recommend Rule is created or updated, depending on whether a Recommend Rule with the same objectID already exists.
You may also specify true for clearExistingRules, in which case the batch will atomically replace all the existing Recommend Rules.
Recommend Rules are similar to Search Rules, except that the conditions and consequences apply to a source item instead of a query. The main differences are the following:
- Conditions
patternandanchoringare unavailable. - Condition
filterstriggers if the source item matches the specified filters. - Condition
filtersaccepts numeric filters. - Consequence
paramsonly covers filtering parameters. - Consequence
automaticFacetFiltersdoesn’t require a facet value placeholder (it tries to match the data source item’s attributes instead).
Usage
Required ACL:
editSettings
Copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import "github.com/algolia/algoliasearch-client-go/v4/algolia/recommend"
client, err := recommend.NewClient("ALGOLIA_APPLICATION_ID", "ALGOLIA_API_KEY")
if err != nil {
// The client can fail to initialize if you pass an invalid parameter.
panic(err)
}
response, err := client.BatchRecommendRules(client.NewApiBatchRecommendRulesRequest(
"ALGOLIA_INDEX_NAME", recommend.RecommendModels("related-products")))
if err != nil {
// handle the eventual error
panic(err)
}
Did you find this page helpful?