elastic / elasticsearch-rails

Elasticsearch integrations for ActiveModel/Record and Ruby on Rails
Apache License 2.0
3.07k stars 797 forks source link

Illegal argument "type" sent in all requests upgrading to 8.x #1049

Open cjba7 opened 1 year ago

cjba7 commented 1 year ago

Aloha,

The ruby API gem, 'elasticsearch-api', alongside this gem seem to send a parameter on all requests when using 8.5 (also tested on 8.4 and 8.3).

At present I've got 7.5.0 in the Gemfile and all works as expected with an ES8.5 cluster.

Working

Gemfile
gem 'elasticsearch', '7.5.0'
gem 'elasticsearch-api', '7.5.0'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'

Gemfile.lock
elasticsearch (7.5.0)
  elasticsearch-api (= 7.5.0)
  elasticsearch-transport (= 7.5.0)
elasticsearch-api (7.5.0)
  multi_json
elasticsearch-model (7.2.1)
  activesupport (> 3)
  elasticsearch (~> 7)
  hashie
elasticsearch-rails (7.2.1)
elasticsearch-transport (7.5.0)
  faraday (>= 0.14, < 1)
  multi_json

Kerploding

Gemfile
gem 'elasticsearch', '8.5.0'
gem 'elasticsearch-api', '8.5.0'
gem 'elasticsearch-model'
gem 'elasticsearch-rails'

Gemfile.lock
elastic-transport (8.1.0)
  faraday (< 3)
  multi_json
elasticsearch (8.5.0)
  elastic-transport (~> 8)
  elasticsearch-api (= 8.5.0)
elasticsearch-api (8.5.0)
  multi_json
elasticsearch-model (7.1.1)
  activesupport (> 3)
  elasticsearch (> 1)
  hashie
elasticsearch-rails (7.2.1)

Example

2.7.6 :001 > Car.__elasticsearch__.search({}).results.count
ETHON: performed EASY effective_url=http://localhost:10005/cars/_search?type response_code=400 return_code=ok total_time=0.00252
curl -X POST -H 'Authorization: Basic Og==, x-elastic-client-meta: es=8.5.0,rb=2.7.6,t=8.1.0,fd=0.17.6,ty=1.4.0, User-Agent: elastic-transport-ruby/8.1.0 (RUBY_VERSION: 2.7.6; darwin x86_64; Faraday v0.17.6), Content-Type: application/json' 'http://localhost:9200/cars/_search?pretty&type' -d '{}'

# 2022-11-24T12:35:04+01:00 [400] (0.004s)
#
# {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"request [/cars/_search] contains unrecognized parameter: [type]"}],"type":"illegal_argument_exception","reason":"request [/cars/_search] contains unrecognized parameter: [type]"},"status":400}

Traceback (most recent call last):
        2: from (irb):1
        1: from (irb):1:in `count'
Elastic::Transport::Transport::Errors::BadRequest ([400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"request [/cars/_search] contains unrecognized parameter: [type]"}],"type":"illegal_argument_exception","reason":"request [/cars/_search] contains unrecognized parameter: [type]"},"status":400})

type appears to be added here: https://github.com/elastic/elasticsearch-rails/blob/main/elasticsearch-model/lib/elasticsearch/model/searching.rb#L57-L59

However we can see here in the comments the allowed parameters does not allow type: https://github.com/elastic/elasticsearch-ruby/blob/main/elasticsearch-api/lib/elasticsearch/api/actions/search.rb#L26-L72

Main reason for our upgrade

We need to start using ES Cloud ID and API key which, according to Elasticsearch support, is not supported in gems of 7.5 versions.

woto commented 1 year ago

Damn. Also stucked with this problem in the middle of update of 'elasticsearch' gem and updating to Elasticsearch 8.7.0 :( Any solution/fork yet?