Skip to content

Instantly share code, notes, and snippets.

@denvit
Last active June 30, 2023 18:20
Show Gist options
  • Save denvit/72463d4f9cc90ee33c29a808d9caacbd to your computer and use it in GitHub Desktop.
Save denvit/72463d4f9cc90ee33c29a808d9caacbd to your computer and use it in GitHub Desktop.
Ruby script to get a list of records in Algolia index
# 1. Install ruby using brew
# 3. Run in terminal: gem install algoliasearch
# 4. Run this script in terminal: ruby script.rb
require 'json'
require 'algoliasearch'
Algolia.init(application_id: '<insert id here>', api_key: '<insert admin key here>')
index = Algolia::Index.new('< name of your index >')
hits = []
index.browse({ query: '', attributesToRetrieve: ['objectID', 'name', 'sku'] }) do |hit|
hits.push(hit)
end
File.write('algolia_records.json', hits.to_json)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment