Install the Ruby API client
Install the Ruby client using RubyGems:
gem install algoliasearch
If you are a Ruby on Rails user, you are probably looking for the algoliasearch-rails gem.
For testing purposes, you might be interested in seeing how to mock Algolia’s API calls
To begin, you will need to initialize the client. In order to do this you will need your Application ID and API Key. You can find both on your Algolia account.
require 'rubygems' require 'algoliasearch' Algolia.init(application_id: 'YourApplicationID', api_key: 'YourAPIKey') index = Algolia::Index.new('your_index_name')
You need to replace
your_index_name by the name of the index you want to use. If you want to target an existing index you can find the name from the dashboard. If the index does not exist you can choose any name and it will be created when you perform an add objects or a set settings operation.
If an api key is displayed in the previous snippet it is your ADMIN API Key. To maintain security, never use your ADMIN API Key on your frontend or share it with anyone. In your frontend, use the SEARCH ONLY API Key or any other key that has search only rights.
Make sure you don’t use any sensitive or personally identifiable information (PII) as your index name, including customer names, user IDs, or email addresses. Index names appear in network requests and should be considered publicly available.
Did you find this page helpful?
We're always looking for advice to help improve our documentation!
Please let us know what's working (or what's not!).
We're constantly iterating thanks to the feedback we receive.