The examples on this page use
-p
(--profile
) for authentication,
or use the default profile.
For more information, see AuthenticationWork with JSON data
The Algolia CLI works well with other command-line tools, such asjq
for working with JSON data.
Many examples on this page use jq
to transform inputs and outputs to and from JSON.
You can install jq
with your favorite package manager,
or download a binary from the Releases page of the GitHub repository.
Newline-delimited JSON
Newline-delimited JSON (NDJSON), also called JSON lines (JSONL), is a file format that works well for streaming lists of objects. Because each line is its own valid JSON object, you can work with each object separately while you are reading the stream. With a JSON array for example, you would have to read the entire list first, or you would get a JSON parsing error.Convert between JSON and NDJSON
You can convert between JSON and NDJSON withjq
:
Export your Algolia data
To create a backup of your index (records, rules, settings, and synonyms), use the following commands:algolia indices config export
command.
This creates a JSON file which you can import in the dashboard.
Import your Algolia data
To import records, synonyms, settings, or rules from a file, use these commands:synonyms
or rules
instead of objects
.
Settings are in a regular JSON object:
algolia indices config import
command.
The JSON file can be exported from the dashboard,
or with the algolia indices config export
command.
Compare index settings
To compare two index settings, use the Algolia CLI with thediff
and jq
commands.
This example uses process substitution:
jq
is required because the algolia settings
command prints compact JSON output without formatting if it runs in pipes,
which makes it difficult to see the differences.INDEX_1
and INDEX_2
with the names of the indices you want to compare,
and specify profiles
if your indices aren’t in the default profile.
Copy indices between applications
To copy an index (records, synonyms, synonyms, rules) between two Algolia applications, you can list all objects with thebrowse
command first,
and pipe this into an import command:
--application-id
and --api-key
options.
For more information,
see Authentication.
Copy specific index settings
You can usejq
to filter the output from the algolia settings get
command so that only specific index settings are copied.
For example,
to copy all index settings except queryLanguages
and
indexLanguages
, run:
Change settings while copying
You can change the output from thealgolia settings get
command with jq
.
For example, to change the queryLanguages
and indexLanguages
settings to French, run:
Find records with missing attributes
Filter the results from thealgolia objects browse
command with jq
.
For example, to find records without a name
attribute:
--attributesToRetrieve
option only includes the name
attribute in the API response.
The jq
command first selects all elements without a name
attribute and then returns a list of their object IDs.
You can turn this into a comma-separated list by adding | join(",")
to the command.
You can combine this with the algolia objects delete command
to delete all records with a missing attribute.