elastic/elasticsearch-rails

create_index! raises undefined method transport @ 7.2.0

plainlystated opened this issue ยท 9 comments

Upgrading from 7.1.1 -> 7.2.0. The Changelog mentions "Updates transport references" which sounds related but I couldn't find any further explanation.

I'm hitting this in a spec, on the line:

Edition.__elasticsearch__.create_index!(force: true)

The stack trace:

NoMethodError:
       undefined method `transport' for #<Elasticsearch::Transport::Transport::HTTP::Faraday:0x000055dd1927c0a8>
       Did you mean?  transliterate
     # /usr/local/bundle/gems/elasticsearch-model-7.2.0/lib/elasticsearch/model/indexing.rb:293:in `rescue in delete_index!'
     # /usr/local/bundle/gems/elasticsearch-model-7.2.0/lib/elasticsearch/model/indexing.rb:289:in `delete_index!'
     # /usr/local/bundle/gems/elasticsearch-model-7.2.0/lib/elasticsearch/model/indexing.rb:248:in `create_index!'
     # ./spec/lib/repo/search_spec.rb:6:in `block (2 levels) in <top (required)>'

Not sure if I'm doing something wrong or there is a bug related to a recent transport change.

I am experiencing the same bug.

For me it will only happen when I do create_index!(force: true) on an index that does not exist.

  • create_index! - works
  • create_index!(force: true) - works if index already exists.

I tried running the specs locally, in the test for the method that fails I get:

client.transport
=>
#<Elasticsearch::Transport::Client:0x00007ffc805e69b8
...

when I check in my Rails-code and run:

Document.__elasticsearch__.client
=>
#<Elasticsearch::Transport::Client:0x00007f89166235d0
...

Document.__elasticsearch__.client.transport
=>
#<Elasticsearch::Transport::Transport::HTTP::Faraday:0x00007f89166221f8
...

So it seems like the test-double for client is setup incorrectly.

I am experiencing the same bug.

same three โœŒ๏ธ .

It is related to changes introduced in this PR #999
Updating to elasticsearch 7.14 fixes this error, however now my rake db:setup is blowing up with:

NoMethodError: undefined method `tracer=' for #<Elasticsearch::Transport::Client

Thanks for reporting this, I'm going to look into it and release a fix as soon as possible.

sled commented

Same here:

MyModel.__elasticsearch__.create_index!(force: true)

results in:

NoMethodError (undefined method `transport' for #<Elasticsearch::Transport::Transport::HTTP::Faraday:0x00007ff960ea6f08>)

the error stems from here:

https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-model/lib/elasticsearch/model/indexing.rb#L293
https://github.com/elastic/elasticsearch-rails/blob/master/elasticsearch-model/lib/elasticsearch/model/indexing.rb#L293

the nested transport looks like a typo: client.transport.transport

If I inspect it on the rails console I get:

irb(main):014:0> MyModel.__elasticsearch__.client.transport.class
=> Elasticsearch::Transport::Transport::HTTP::Faraday

irb(main):015:0> MyModel.__elasticsearch__.client.transport.respond_to?(:transport)
=> false
1st8 commented

Fixed for me after upgrading elasticsearch to 7.15.0. The fix might have been in an earlier version though.

Any news on this? I'm still having this issue with elasticsearch-rails 7.2.1.

In the meantime, I was able to workaround it with this:

class Elasticsearch::Transport::Transport::HTTP::Faraday
  def transport
    self
  end
end

Any news on this? I'm still having this issue with elasticsearch-rails 7.2.1.

In the meantime, I was able to workaround it with this:


class Elasticsearch::Transport::Transport::HTTP::Faraday

  def transport

    self

  end

end

We realized that we cannot upgrade the client anymore after the branching and license change because we use other provider than Elasticsearch. I guess it is time to do the work to switch to Opensearch library.

I'm having the same issue.
This is the workaround I'm using right now.
#1004 (comment)