Framework integration / Rails / Advanced

Sometimes it can be necessary to access the Algolia API client or the model indices directly.

Access the Algolia API client

The client is available as a singleton and uses the Algolia credentials you added to your Rails configuration.

For example, to create a new API key:

1
key = AlgoliaSearch.client.add_api_key({ acl: ['search'], 'indexes': ['*_development', '*_development.tmp'] })

Access model indices

To access the index used by a model, use the index class method. This method follows your naming configuration, such as per-environment settings or custom names.

1
2
index = Contact.index
# index.get_settings, index.partial_update_object, ...
Did you find this page helpful?