Skip to content

Instantly share code, notes, and snippets.

@nicksnell
Created July 25, 2018 15:48
Show Gist options
  • Save nicksnell/5b4e61ad64ae7ac1dba7795cd6a703d4 to your computer and use it in GitHub Desktop.
Save nicksnell/5b4e61ad64ae7ac1dba7795cd6a703d4 to your computer and use it in GitHub Desktop.
Tool for exporting indexes from Algolia
"""
Export an Algolia Index to JSON.
Usage: ALGOLIA_KEY=<some key> ALGOLIA_SECRET=<some secret> ALGOLIA_INDEX=<some index> python algolia_export.py
"""
import os
import json
from algoliasearch import algoliasearch
client = algoliasearch.Client(
os.environ.get('ALGOLIA_KEY'),
os.environ.get('ALGOLIA_SECRET')
)
index = client.init_index(os.environ.get('ALGOLIA_INDEX'))
hits = []
for hit in index.browse_all({"query": ""}):
hits.append(hit)
with open('dump.json', 'w') as f:
json.dump(hits, f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment