algolia/algoliasearch-client-ruby

index.set_settings => { forwardToReplicas: true } as options raises an error

skelz0r opened this issue · 0 comments

  • Algolia Client Version: 2.0.4 (latest)
  • Language Version: Ruby

Description

When I try to set settings and forward to replicas it doesn't work.

index.set_settings(settings_hash, { forwardToReplicas: true })

Steps To Reproduce

Simply past the example from documentation https://www.algolia.com/doc/guides/managing-results/refine-results/sorting/how-to/set-settings-and-forward-to-replicas/?client=ruby#using-the-api

index.set_settings({ searchableAttributes: ['name', 'description'] }, { forwardToReplicas: true })

The error:

         4: from /Users/skelz0r/.rvm/gems/ruby-2.6.6/gems/algolia-2.0.4/lib/algolia/search_index.rb:990:in `set_settings'
         3: from /Users/skelz0r/.rvm/gems/ruby-2.6.6/gems/algolia-2.0.4/lib/algolia/transport/transport.rb:38:in `write'
         2: from /Users/skelz0r/.rvm/gems/ruby-2.6.6/gems/algolia-2.0.4/lib/algolia/transport/transport.rb:50:in `request'
         1: from /Users/skelz0r/.rvm/gems/ruby-2.6.6/gems/algolia-2.0.4/lib/algolia/transport/transport.rb:50:in `each'
/Users/skelz0r/.rvm/gems/ruby-2.6.6/gems/algolia-2.0.4/lib/algolia/transport/transport.rb:72:in `block in request': Invalid object attributes: forwardToReplicas near line:1 column:128 (Algolia::AlgoliaHttpError)

Inspecting

The set_settings method is defined here:

def set_settings(settings, opts = {})

When we dig another method (like save_synonyms) I noticed that the forwardToReplicas is directly build on the path parameter (

path_encode('/1/indexes/%s/synonyms/batch', @name) + handle_params({ forwardToReplicas: forward_to_replicas, replaceExistingSynonyms: replace_existing_synonyms }),
) which is not the case for set_settings

Workaround

After some digging in the Algolia::Transport::Transport class I managed to find a way to pass my parameter:

index.set_settings({ searchableAttributes: ['name', 'description'] }, { params: { forwardToReplicas: true }})

But it's not consistent with save_synonyms (and perhaps with other methods).