jq.
For more information, see Work with JSON data.
Export your Algolia data
To create a backup of your index (records, rules, settings, and synonyms), run these commands:algolia indices config export command.
This command creates a JSON file that you can import in the dashboard.
Import your Algolia data
To import records from a file, run one of these commands:synonyms or rules instead of objects.
To import settings from a JSON object, run:
algolia indices config import command.
You can export the JSON file from the dashboard,
or with the algolia indices config export command.
Compare index settings
To compare the settings of two indices, use the Algolia CLI with thediff and jq commands.
This example uses process substitution:
If the output of
algolia settings get goes to a pipe, the command prints compact JSON.
The jq command formats the JSON so that you can see the differences.INDEX_1 and INDEX_2 with the names of the indices you want to compare.
If the indices aren’t in your current application,
set the ALGOLIA_APPLICATION_ID and ALGOLIA_API_KEY environment variables.
Copy indices between applications
To copy an index (records, synonyms, rules, and settings) between two Algolia applications, export each part with abrowse or get command.
Then pipe the output into the matching import command.
Environment variables take precedence over the --application-id and --api-key options.
To make sure each command uses the right application,
set the credentials as environment variables for each command.
This syntax works in Bash and Zsh:
APP_ID_1/API_KEY_1 and APP_ID_2/API_KEY_2 with the credentials
of the source and destination applications.
Copy specific index settings
To copy only some index settings, filter the output ofalgolia settings get with jq.
For example,
to copy all index settings except queryLanguages and
indexLanguages, run:
Change settings while copying
To change index settings while you copy them, edit the output ofalgolia settings get with jq.
For example, to change the queryLanguages and indexLanguages settings to French, run:
Reindex without downtime
To replace all records in an index without interrupting search, build the new version in a temporary index, then move it over the live index.INDEX keep returning the old records until the move completes.
In a script or another non-interactive shell, add --confirm to the copy and move commands.
Search an index
To test a query from the terminal, pass it toalgolia search:
--filters, --hitsPerPage, and --page:
genres:Animation, work only on attributes in attributesForFaceting.
To keep the response small,
select the response properties and record attributes to return:
jsonpath output format:
Check attribute types and frequency
To see how consistent your records are, runalgolia indices analyze.
This command shows how often each attribute occurs and which types it has.
Use this report to find attributes that some records don’t have,
or attributes with the wrong type, such as a null in a numeric attribute:
--no-limit.
For large indices, this can take a long time.
To see how often each value of one attribute occurs, add --only:
Find records with missing attributes
To find records that don’t have an attribute, filter the output ofalgolia objects browse with jq.
For example, to find records without a name attribute, run:
--attributesToRetrieve flag includes only the name attribute in the API response.
The jq command selects all records without a name attribute.
Then it returns a list of their object IDs.
To get a comma-separated list, add | join(",") to the end of the jq filter.
Delete records with a missing attribute
To delete all records that don’t have an attribute, combine the previous command withalgolia objects delete.
--confirm to the delete command.
Create a search-only API key
To create a key for a frontend that can search only one index, set thesearch ACL and limit the key to that index:
--api-key and add --validity.
For more information, see algolia apikeys create.
Work with JSON data
You can use the Algolia CLI with other command-line tools, such asjq to process JSON data.
You can install jq with your 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 for streams of JSON objects. Each line is a valid JSON object, so you can process each object while you read the stream. With a JSON array, you must read the full array before you can parse it.Convert between JSON and NDJSON
You can convert between JSON and NDJSON withjq: