POST /1/indexes/{indexName}/rules/batch

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.

Servers

Path parameters

Name Type Required Description
indexName String Yes

Name of the index on which to perform the operation.

Request headers

Name Type Required Description
Content-Type String Yes The media type of the request body.

Default value: "application/json"

Query parameters

Name Type Required Description
clearExistingRules Boolean No

Whether existing rules should be deleted before adding this batch.

forwardToReplicas Boolean No

Whether changes are applied to replica indices.

Request body fields

Name Type Required Description
[] Array Yes
[].description String No

Description of the rule's purpose to help you distinguish between different rules.

[].conditions[] Array No

Conditions that trigger a rule.

Some consequences require specific conditions or don't require any condition. For more information, see Conditions.

[].conditions[].filters String No

Filters that trigger the rule.

You can add add filters using the syntax facet:value so that the rule is triggered, when the specific filter is selected. You can use filters on its own or combine it with the pattern parameter.

[].conditions[].anchoring String No

Which part of the search query the pattern should match:

  • startsWith. The pattern must match the beginning of the query.
  • endsWith. The pattern must match the end of the query.
  • is. The pattern must match the query exactly.
  • contains. The pattern must match anywhere in the query.

Empty queries are only allowed as patterns with anchoring: is.

Possible values:

  • "startsWith"
  • "contains"
  • "is"
  • "endsWith"
[].conditions[].context String No

An additional restriction that only triggers the rule, when the search has the same value as ruleContexts parameter. For example, if context: mobile, the rule is only triggered when the search request has a matching ruleContexts: mobile. A rule context must only contain alphanumeric characters.

[].conditions[].alternatives Boolean No

Whether the pattern should match plurals, synonyms, and typos.

Default value: false

[].conditions[].pattern String No

Query pattern that triggers the rule.

You can use either a literal string, or a special pattern {facet:ATTRIBUTE}, where ATTRIBUTE is a facet name. The rule is triggered if the query matches the literal string or a value of the specified facet. For example, with pattern: {facet:genre}, the rule is triggered when users search for a genre, such as "comedy".

[].consequence Object Yes

Effect of the rule.

For more information, see Consequences.

[].consequence.promote[] Array No

Records you want to pin to a specific position in the search results.

You can promote up to 300 records, either individually, or as groups of up to 100 records each.

[].consequence.filterPromotes Boolean No

Whether promoted records must match an active filter for the consequence to be applied.

This ensures that user actions (filtering the search) are given a higher precendence. For example, if you promote a record with the color: red attribute, and the user filters the search for color: blue, the "red" record won't be shown.

Default value: false

[].consequence.hide[] Array No

Records you want to hide from the search results.

[].consequence.hide[].objectID String Yes

Unique record identifier.

[].consequence.userData Object No

A JSON object with custom data that will be appended to the userData array in the response. This object isn't interpreted by the API and is limited to 1 kB of minified JSON.

[].enabled Boolean No

Whether the rule is active.

Default value: true

[].objectID String Yes

Unique identifier of a rule object.

[].validity[] Array No

Time periods when the rule is active.

[].validity[].until Integer Yes

When the rule should stop to be active, in Unix epoch time.

[].validity[].from Integer Yes

When the rule should start to be active, in Unix epoch time.

How to start integrating

  1. Add HTTP Task to your workflow definition.
  2. Search for the API you want to integrate with and click on the name.
    • This loads the API reference documentation and prepares the Http request settings.
  3. Click Test request to test run your request to the API and see the API's response.