The examples on this page use the application you selected with
algolia application select.
Where two applications are involved, they pass credentials with the --application-id and --api-key flags.
For more information, see Authentication.Work 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:
Command line
Export your Algolia data
To create a backup of your index (records, rules, settings, and synonyms), use the following commands:Command line
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:Command line
synonyms or rules instead of objects.
Settings are in a regular JSON object:
Command line
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:
Command line
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 pass --application-id and --api-key
if the indices aren’t in your selected application.
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:
Command line
APP_ID_1/API_KEY_1 and APP_ID_2/API_KEY_2 with the credentials
of the source and destination applications.
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:
Command line
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:
Command line
Find records with missing attributes
Filter the results from thealgolia objects browse command with jq.
For example, to find records without a name attribute:
Command line
--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.
Command line