Home > OS >  Argument Error with ElasticSearch in ruby 3.1
Argument Error with ElasticSearch in ruby 3.1

Time:10-02

I recently upgraded the ruby version of my Rails application from 2.7 to 3.1 but after that I am facing issues related to elasticsearch. When I start the elasticsearch server and run the below command:

RAILS_ENV=development bundle exec rake environment elasticsearch:import:model CLASS='ClinicalEquivalence' FORCE=y

It gives me an Argument error. Below is the error stack:

ArgumentError: wrong number of arguments (given 1, expected 0)
Users/apple/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activerecord-6.1.5/lib/active_record/relation/batches.rb:128:in `find_in_batches'
Users/apple/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/activerecord-6.1.5/lib/active_record/querying.rb:22:in `find_in_batches'
Users/apple/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/bundler/gems/elasticsearch-rails-dbd617ecc25c/elasticsearch-model/lib/elasticsearch/model/proxy.rb:96:in `method_missing'

Below is the snapshot of elasticsearch gems I am using:

elasticsearch (6.8.1)
elasticsearch-api (= 6.8.1)
elasticsearch-transport (= 6.8.1)
elasticsearch-model (6.1.1)
elasticsearch-rails (6.1.1)

It was working perfectly fine in previous versions of ruby but suddenly breaking in v 3.1. I suspect this is happening because using the last argument as keyword parameters is deprecated in ruby 3.1. Please let me know if anybody know how can I fix this preferably without having to upgrade the elasticsearch that I am using.

CodePudding user response:

They actually fixed this bug in elasticsearch-rails 6.1.1 as seen here https://github.com/elastic/elasticsearch-rails/blob/6.1.1/CHANGELOG.md

But if you investigate the files in the uploaded gem you can see that they didn't push this change, probably by an accident? https://my.diffend.io/gems/elasticsearch-rails/6.1.0/6.1.1

Best way to deal with it is to specify the commit in Gemfile

gem 'elasticsearch-rails', git: "https://github.com/elastic/elasticsearch-rails", tag: "6.1.1", ref: "f22d97e0cd629475bed48be3b1219741a46ba4b9"

One more advice is to upgrade one major version of Ruby at a time.

  • Related