algolia gem is version 3.
This page helps you upgrade from version 2
and explains the breaking changes you need to address.
Algolia generates the version 3 clients from OpenAPI specifications,
which provides consistent behavior across all languages and up-to-date API coverage.
The main architectural change is the removal of the init_index pattern:
all methods are now on the client instance directly, with index_name as a parameter.
For the full list of changes, see the Ruby changelog.
Update your dependencies
Update thealgolia gem to version 3:
The gem name stays
algolia.
Don’t confuse it with the older algoliasearch gem, which installs version 1.Update imports
The module paths for API clients changed.Algolia::Search::Client is now Algolia::SearchClient,
and all other clients follow the same flattened pattern.
Ruby
Ruby
Update client initialization
Besides the class name change, client creation follows the same pattern. The constructor still accepts your application ID and API key:Ruby
init_index no longer exists.
Remove init_index
This is the most significant change when upgrading.
Version 2 relied on an index object with methods called on it.
In version 3, all methods belong to the client instance,
with index_name as a parameter.
Ruby
Update search calls
Search a single index
Theindex.search method is now client.search_single_index.
Pass the index name and search parameters as positional arguments:
Ruby
Search multiple indices
Theclient.multiple_queries method is now client.search.
Each request in the array requires an index_name:
Ruby
Search for facet values
Theindex.search_for_facet_values method becomes client.search_for_facet_values
with an index_name parameter:
Ruby
Update indexing operations
In version 3, indexing methods are on the client instead of the index object, withindex_name as a parameter.
Add or replace records
Ruby
Partially update records
Ruby
Delete records
Ruby
Update settings, synonyms, and rules
Get and set settings
Ruby
Save synonyms and rules
Ruby
In version 2,
index.replace_all_rules and index.replace_all_synonyms replaced all rules or synonyms.
In version 3, use client.save_rules or client.save_synonyms with clear_existing_rules or replace_existing_synonyms set to true.Update index management
Thecopy_index, move_index, copy_rules, copy_synonyms, and copy_settings
methods are all replaced by a single operation_index method.
Copy an index
Ruby
Move (rename) an index
Ruby
Copy only rules or settings
In version 3, use thescope parameter to limit the operation to specific data:
Ruby
Update task handling
Version 2 supported chaining.wait on operations.
Version 3 replaces this pattern with dedicated wait helpers or the built-in wait_for_tasks parameter.
Ruby
wait_for_task: wait until indexing operations are done.wait_for_app_task: wait for application-level tasks.wait_for_api_key: wait for API key operations.
Method changes reference
The following tables list all method names that changed between version 2 and version 3.A few methods were also renamed:
list_indexes is now list_indices,
and get_top_user_id is now get_top_user_ids.Search API client
| Version 2 (legacy) | Version 3 (current) | |
|---|---|---|
client.add_api_key | → | client.add_api_key |
client.add_api_key.wait | → | client.wait_for_api_key |
client.clear_dictionary_entries | → | client.batch_dictionary_entries |
client.copy_index | → | client.operation_index |
client.copy_rules | → | client.operation_index |
client.copy_synonyms | → | client.operation_index |
client.delete_api_key | → | client.delete_api_key |
client.delete_dictionary_entries | → | client.batch_dictionary_entries |
client.generate_secured_api_key | → | client.generate_secured_api_key |
client.get_api_key | → | client.get_api_key |
client.get_secured_api_key_remaining_validity | → | client.get_secured_api_key_remaining_validity |
client.get_top_user_id | → | client.get_top_user_ids |
client.list_api_keys | → | client.list_api_keys |
client.list_indexes | → | client.list_indices |
client.move_index | → | client.operation_index |
client.multiple_batch | → | client.multiple_batch |
client.multiple_queries | → | client.search |
client.replace_dictionary_entries | → | client.batch_dictionary_entries |
client.restore_api_key | → | client.restore_api_key |
client.save_dictionary_entries | → | client.batch_dictionary_entries |
client.update_api_key | → | client.update_api_key |
index.batch | → | client.batch |
index.browse_objects | → | client.browse_objects |
index.browse_rules | → | client.browse_rules |
index.browse_synonyms | → | client.browse_synonyms |
index.clear_objects | → | client.clear_objects |
index.clear_rules | → | client.clear_rules |
index.clear_synonyms | → | client.clear_synonyms |
index.copy_settings | → | client.operation_index |
index.delete | → | client.delete_index |
index.delete_by | → | client.delete_by |
index.delete_object | → | client.delete_object |
index.delete_objects | → | client.delete_objects |
index.delete_rule | → | client.delete_rule |
index.delete_synonym | → | client.delete_synonym |
index.find_object | → | client.search_single_index |
index.get_object | → | client.get_object |
index.get_objects | → | client.get_objects |
index.get_rule | → | client.get_rule |
index.get_settings | → | client.get_settings |
index.get_synonym | → | client.get_synonym |
index.get_task | → | client.get_task |
index.partial_update_object | → | client.partial_update_object |
index.partial_update_objects | → | client.partial_update_objects |
index.replace_all_objects | → | client.replace_all_objects |
index.replace_all_rules | → | client.save_rules |
index.replace_all_synonyms | → | client.save_synonyms |
index.save_object | → | client.save_object |
index.save_objects | → | client.save_objects |
index.save_rule | → | client.save_rule |
index.save_rules | → | client.save_rules |
index.save_synonym | → | client.save_synonym |
index.save_synonyms | → | client.save_synonyms |
index.search | → | client.search_single_index |
index.search_for_facet_values | → | client.search_for_facet_values |
index.search_rules | → | client.search_rules |
index.search_synonyms | → | client.search_synonyms |
index.set_settings | → | client.set_settings |
index.{operation}.wait | → | client.wait_for_task |
Recommend API client
| Version 2 (legacy) | Version 3 (current) | |
|---|---|---|
client.get_frequently_bought_together | → | client.get_recommendations |
client.get_recommendations | → | client.get_recommendations |
client.get_related_products | → | client.get_recommendations |