I had configured elasticsearch, and function of "index" & "search" works on my model name "Discussion".
But I got error of "ArgumentError: Invalid arguments!" when I run below command:
Here is the content of log when executing these commands:
/Users/myuser/.rvm/gems/ruby-1.9.3-p448/gems/activerecord-import-0.5.0/lib/activerecord-import/import.rb:199:in import'
/Users/myuser/.rvm/gems/ruby-1.9.3-p448/gems/elasticsearch-rails-0.1.4/lib/elasticsearch/rails/tasks/import.rb:62:inblock (3 levels) in block (4 levels) in <top (required)>'
/Users/myuser/.rvm/gems/ruby-1.9.3-p448/gems/elasticsearch-rails-0.1.4/lib/elasticsearch/rails/tasks/import.rb:86:ineach'
/Users/myuser/.rvm/gems/ruby-1.9.3-p448/gems/elasticsearch-rails-0.1.4/lib/elasticsearch/rails/tasks/import.rb:86:in block (3 levels) in <top (required)>'
/Users/myuser/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:ineval'
/Users/myuser/.rvm/gems/ruby-1.9.3-p448/bin/ruby_noexec_wrapper:14:in `
I found out the issue. We had used gem "gem 'activerecord-import'" within our system. And when we uninstall this gem, everything works fine.
@afterclassroom The gem might have clashed with the Rake task, but the import process could be also started from code, MyModel.__elasticsearch__.import, using the proxy method, to bypass the import method from the other gem.
I've encountered the same problem. I have both activerecord-import and elasticsearch-model included in my models. Attempting MyModel.__elasticsearch__.import results in an error:
ArgumentError: Invalid arguments!
from /gems/activerecord-import-0.5.0/lib/activerecord-import/import.rb:199:in `import'
from /gems/elasticsearch-model-0.1.5/lib/elasticsearch/model/proxy.rb:80:in `method_missing'
elasticsearch/model/proxy.rb:80 appears to invoke the import method on the target (MyModel class, and therefore invoking the import method included from activerecord-import). It looks like the OP removed the gem to solve their problem, but it would be nice to be able to use both gems side by side.
@avinmathew The problem is that the Rake task calls Model.import, not Model.__elasticsearch__.import. Also, you have to require the activerecord-import gem first, so its import() method is respected.
Attempting
MyModel.__elasticsearch__.import(...) results in an error
So, when I add this:
require 'activerecord-import'
to the activerecord_article.rb example, I get this:
> Article.__elasticsearch__.import
Article Load (13.7ms) SELECT "articles".* FROM "articles" ORDER BY "articles"."id" ASC LIMIT 1000
2014-09-15 09:10:51 +0200: POST http://localhost:9200/articles/article/_bulk?type=article [status:200, request:0.085s, query:0.024s]
2014-09-15 09:10:51 +0200: > {"index":{"_id":1}}
{"id":1,"title":"Foo","published_at":null,"created_at":"2014-09-15T07:09:04Z","updated_at":"2014-09-15T07:09:04Z"}
{"index":{"_id":2}}
{"id":2,"title":"Bar","published_at":null,"created_at":"2014-09-15T07:09:04Z","updated_at":"2014-09-15T07:09:04Z"}
{"index":{"_id":3}}
{"id":3,"title":"Foo Foo","published_at":null,"created_at":"2014-09-15T07:09:04Z","updated_at":"2014-09-15T07:09:04Z"}
2014-09-15 09:10:51 +0200: < {"took":24,"errors":false,"items":[{"index":{"_index":"articles","_type":"article","_id":"1","_version":2,"status":200}},{"index":{"_index":"articles","_type":"article","_id":"2","_version":2,"status":200}},{"index":{"_index":"articles","_type":"article","_id":"3","_version":2,"status":200}}]}
=> 0
> Article.import
ArgumentError: Invalid arguments!
from /Users/karmi/.rbenv/versions/2.1.2/lib/ruby/gems/2.1.0/gems/activerecord-import-0.5.0/lib/activerecord-import/import.rb:199:in `import'
Fixed the error in the Rake task in attached commit...
Most helpful comment
@afterclassroom The gem might have clashed with the Rake task, but the import process could be also started from code,
MyModel.__elasticsearch__.import, using the proxy method, to bypass the import method from the other gem.