elasticsearch-rails icon indicating copy to clipboard operation
elasticsearch-rails copied to clipboard

create_index! raises undefined method transport @ 7.2.0

Open plainlystated opened this issue 3 years ago • 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.

plainlystated avatar Aug 12 '21 02:08 plainlystated

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.

davidwessman avatar Aug 12 '21 06:08 davidwessman

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.

davidwessman avatar Aug 12 '21 06:08 davidwessman

I am experiencing the same bug.

same three :v: .

It is related to changes introduced in this PR https://github.com/elastic/elasticsearch-rails/pull/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

sonalkr132 avatar Aug 20 '21 17:08 sonalkr132

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

picandocodigo avatar Aug 23 '21 21:08 picandocodigo

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

sled avatar Aug 24 '21 21:08 sled

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

1st8 avatar Oct 07 '21 12:10 1st8

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

pdfrod avatar Mar 23 '22 12:03 pdfrod

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.

davidwessman avatar Mar 25 '22 08:03 davidwessman

I'm having the same issue. This is the workaround I'm using right now. https://github.com/elastic/elasticsearch-rails/issues/1004#issuecomment-897372219

kimegede avatar Jan 31 '23 09:01 kimegede