Elasticsearch-rails: Rails Application Template 03-expert.rb - ArgumentError: wrong number of arguments (given 1, expected 0)

Created on 7 Apr 2021  路  1Comment  路  Source: elastic/elasticsearch-rails

I have successfully loaded templates 01-basic.rb and 02-pretty.rb, however the load of the 03-expert.rb template fails with an ArgumentError: wrong number of arguments (given 1, expected 0) message. The error occurs when the template's line 325 rake "environment elasticsearch:import:model CLASS='Article' BATCH=100 FORCE=y" is executed, resulting in the following output:

rake aborted!
ArgumentError: wrong number of arguments (given 1, expected 0)
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/relation/batches.rb:128:in 'find_in_batches'
/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/querying.rb:22:in 'find_in_batches'
/usr/local/bundle/gems/elasticsearch-model-7.1.1/lib/elasticsearch/model/proxy.rb:121:in 'method_missing'
/usr/local/bundle/gems/elasticsearch-model-7.1.1/lib/elasticsearch/model/adapters/active_record.rb:105:in '__find_in_batches'
/usr/local/bundle/gems/elasticsearch-model-7.1.1/lib/elasticsearch/model/importing.rb:161:in 'import'
/usr/local/bundle/gems/elasticsearch-rails-7.1.1/lib/elasticsearch/rails/tasks/import.rb:80:in 'block (3 levels) in \' /usr/local/bin/bundle:23:in 'load'
/usr/local/bin/bundle:23:in '\ Tasks: TOP => elasticsearch:import:model
(See full trace by running task with --trace)

ruby --version && rails --version

ruby 3.0.1p64 (2021-04-05 revision 0fb782ee38) [x86_64-linux]
Rails 6.1.3.1

I'm running the code in Docker version 20.10.5 container in Docker's Desktop for Mac, version 3.2.2.

I'm new to Ruby, Rails and Elasticsearch so I don't know what steps to take next to solve this problem. I did try using 'byebug' in searchable.rb, and have reproduced the var all output from the step before the error and at the error stage in case it is helpful in suggesting what I should attempt next.

(byebug) next
[75, 84] in /usr/local/bundle/gems/elasticsearch-rails-7.1.1/lib/elasticsearch/rails/tasks/import.rb
75: begin
76: klass.__elasticsearch__.client.transport.tracer.level = Logger::WARN
77: rescue NoMethodError; end
78: end
79:
=> 80: total_errors = klass.__elasticsearch__.import force: ENV.fetch('FORCE', false),
81: batch_size: ENV.fetch('BATCH', 1000).to_i,
82: index: ENV.fetch('INDEX', nil),
83: type: ENV.fetch('TYPE', nil),
84: scope: ENV.fetch('SCOPE', nil) do |response|
(byebug) var all
$! = nil
$" = ["enumerator.so", "thread.rb", "rational.so", "complex.so", "ruby2_keywords.rb", "/usr/local/lib/ruby/3.0.0/x86_64-linux/enc/encdb.so", "/usr/local/lib/...
$$ = 31866
$& = " "
$' = "$ rake environment elasticsearch:import:all DIR=app/models\n"
$* = []
$+ = nil
$, = nil
$-0 = "\n"
$-F = nil
$-I = ["/usr/share/eab/searchapp/lib", "/usr/share/eab/searchapp/vendor", "/usr/share/eab/searchapp/app/channels", "/usr/share/eab/searchapp/app/controllers"...
$-W = 1
$-a = false
$-d = false
$-i = nil
$-l = false
$-p = false
$-v = false
$-w = false
$. = 19
$/ = "\n"
$0 = "/usr/local/bin/rake"
$: = ["/usr/share/eab/searchapp/lib", "/usr/share/eab/searchapp/vendor", "/usr/share/eab/searchapp/app/channels", "/usr/share/eab/searchapp/app/controllers",...
$; = nil
$< = ARGF
$> = #>
$? = #
$@ = nil
$ARGV = []
$CGI_ENV = {"REDIS_URL"=>"redis://172.17.0.5:6379", "HOSTNAME"=>"a6fd3b6f4a71", "RUBY_DOWNLOAD_SHA256"=>"d06bccd382d03724b69f674bc46cd6957ba08ed07522694ce44b...
$CHILD_STATUS = #
$CODERAY_DEBUG = false
$DEBUG = false
$DEFAULT_INPUT = ARGF
$DEFAULT_OUTPUT = #>
$ERROR_INFO = nil
$ERROR_POSITION = nil
$FIELD_SEPARATOR = nil
$FILENAME = "FORCE=y"
$FS = nil
$INPUT_LINE_NUMBER = 19
$INPUT_RECORD_SEPARATOR = "\n"
$LAST_MATCH_INFO = #
$LAST_PAREN_MATCH = nil
$LAST_READ_LINE = nil
$LOADED_FEATURES = ["enumerator.so", "thread.rb", "rational.so", "complex.so", "ruby2_keywords.rb", "/usr/local/lib/ruby/3.0.0/x86_64-linux/enc/encdb.so", "/...
$LOAD_PATH = ["/usr/share/eab/searchapp/lib", "/usr/share/eab/searchapp/vendor", "/usr/share/eab/searchapp/app/channels", "/usr/share/eab/searchapp/app/contr...
$MATCH = " "
$NR = 19
$OFS = nil
$ORS = nil
$OUTPUT_FIELD_SEPARATOR = nil
$OUTPUT_RECORD_SEPARATOR = nil
$PID = 31866
$POSTMATCH = "$ rake environment elasticsearch:import:all DIR=app/models\n"
$PREMATCH = " Import all indices from app/models (or use DIR environment variable).\n\n "
$PROCESS_ID = 31866
$PROGRAM_NAME = "/usr/local/bin/rake"
$RS = "\n"
$VERBOSE = false
$\ = nil
$_ = nil
$= " Import all indices fromapp/models(or use DIR environment variable).\n\n " $elasticsearch_url = "http://172.17.0.2:9200" $stderr = #<IO:<STDERR>> $stdin = #<IO:<STDIN>> $stdout = #<IO:<STDOUT>> $thor_runner = false $trace = false $~ = #<MatchData " "> import_model_desc = Import data from your model (pass name as CLASS environment variable). $ rake environment elasticsearch:import:model CLASS='MyModel' ... klass = Article pbar = nil total = 1 total_errors = nil (byebug) next [216, 225] in /usr/local/lib/ruby/gems/3.0.0/gems/rake-13.0.3/lib/rake/task.rb 216: @already_invoked = true 217: 218: invoke_prerequisites(task_args, new_chain) 219: execute(task_args) if needed? 220: rescue Exception => ex => 221: add_chain_to(ex, new_chain) 222: @invocation_exception = ex 223: raise ex 224: end 225: end (byebug) var all $! = #<ArgumentError: wrong number of arguments (given 1, expected 0)> $" = ["enumerator.so", "thread.rb", "rational.so", "complex.so", "ruby2_keywords.rb", "/usr/local/lib/ruby/3.0.0/x86_64-linux/enc/encdb.so", "/usr/local/lib/... $$ = 31866 $& = nil $' = nil $* = [] $+ = nil $, = nil $-0 = "\n" $-F = nil $-I = ["/usr/share/eab/searchapp/lib", "/usr/share/eab/searchapp/vendor", "/usr/share/eab/searchapp/app/channels", "/usr/share/eab/searchapp/app/controllers"... $-W = 1 $-a = false $-d = false $-i = nil $-l = false $-p = false $-v = false $-w = false $. = 21 $/ = "\n" $0 = "/usr/local/bin/rake" $: = ["/usr/share/eab/searchapp/lib", "/usr/share/eab/searchapp/vendor", "/usr/share/eab/searchapp/app/channels", "/usr/share/eab/searchapp/app/controllers",... $; = nil $< = ARGF $> = #<IO:<STDOUT>> $? = #<Process::Status: pid 31867 exit 0> $@ = ["/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/relation/batches.rb:128:infind_in_batches'", "/usr/local/bundle/gems/activerecord-6.1....
$ARGV = []
$CGI_ENV = {"REDIS_URL"=>"redis://172.17.0.5:6379", "HOSTNAME"=>"a6fd3b6f4a71", "RUBY_DOWNLOAD_SHA256"=>"d06bccd382d03724b69f674bc46cd6957ba08ed07522694ce44b...
$CHILD_STATUS = #
$CODERAY_DEBUG = false
$DEBUG = false
$DEFAULT_INPUT = ARGF
$DEFAULT_OUTPUT = #>
$ERROR_INFO = # $ERROR_POSITION = ["/usr/local/bundle/gems/activerecord-6.1.3.1/lib/active_record/relation/batches.rb:128:in find_in_batches'", "/usr/local/bundle/gems/acti... $FIELD_SEPARATOR = nil $FILENAME = "FORCE=y" $FS = nil $INPUT_LINE_NUMBER = 21 $INPUT_RECORD_SEPARATOR = "\n" $LAST_MATCH_INFO = nil $LAST_PAREN_MATCH = nil $LAST_READ_LINE = nil $LOADED_FEATURES = ["enumerator.so", "thread.rb", "rational.so", "complex.so", "ruby2_keywords.rb", "/usr/local/lib/ruby/3.0.0/x86_64-linux/enc/encdb.so", "/... $LOAD_PATH = ["/usr/share/eab/searchapp/lib", "/usr/share/eab/searchapp/vendor", "/usr/share/eab/searchapp/app/channels", "/usr/share/eab/searchapp/app/contr... $MATCH = nil $NR = 21 $OFS = nil $ORS = nil $OUTPUT_FIELD_SEPARATOR = nil $OUTPUT_RECORD_SEPARATOR = nil $PID = 31866 $POSTMATCH = nil $PREMATCH = nil $PROCESS_ID = 31866 $PROGRAM_NAME = "/usr/local/bin/rake" $RS = "\n" $VERBOSE = false $\ = nil $_ = nil $ = nil
$elasticsearch_url = "http://172.17.0.2:9200"
$stderr = #>
$stdin = #>
$stdout = #>
$thor_runner = false
$trace = false
$~ = nil
@actions = [#]
@already_invoked = true
@application = # @arg_names = nil
@comments = []
@invocation_exception = nil
@locations = []
@lock = #
@name = "elasticsearch:import:model"
@order_only_prerequisites = []
@prerequisites = []
@scope = LL("import", "elasticsearch")
ex = wrong number of arguments (given 1, expected 0)
invocation_chain = TOP
new_chain = TOP => elasticsearch:import:model
self = elasticsearch:import:model
task_args = # (byebug)

Most helpful comment

I opened a PR with a fix for this. If you're impatient, you can update your Gemfile entry for elasticsearch-model to use the fix before they merge the fix and release a new version:

gem "elasticsearch-model", github: "indirect/elasticsearch-rails"

>All comments

I opened a PR with a fix for this. If you're impatient, you can update your Gemfile entry for elasticsearch-model to use the fix before they merge the fix and release a new version:

gem "elasticsearch-model", github: "indirect/elasticsearch-rails"
Was this page helpful?
0 / 5 - 0 ratings