Elastic badrequest error: contains unrecognized parameter: [type]

I am using Elasticsearch in a Rails application through the Elasticsearch-rails gem. After creating the indexes, I want to import the data into these indexes. But I am getting the following error:

Elastic::Transport::Transport::Errors::BadRequest ([400] {"error":{"root_cause":[{"type":"illegal_argument_exception","reason":"request [/social_contacts/_bulk] contains unrecognized parameter: [type]"}],"type":"illegal_argument_exception","reason":"request [/social_contacts/_bulk] contains unrecognized parameter: [type]"},"status":400})

I've got confused while googling about this error. So I appreciate it if anyone can help me.

Hello and welcome,

What is the request you are making? And what is the version of Elasticsearch you are using?

It seems that your request is including a type, types were deprecated in Elasticsearch 7.0 (2019) and removed in Elasticsearch 8.

You can read the post explaining this here.

Thanks for the quick response.
I am using these versions:

 elasticsearch (8.12.2)
 elasticsearch-model (7.1.1)
 elasticsearch-rails (7.2.1)

The following snippet of code is my model configuration:

module Searchable
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks

    settings index: { number_of_shards: 1 } do
      mappings dynamic: 'false' do
        # Define your mapping properties here if needed
        indexes :name
      end
    end

    def self.search(query)
      # Your search logic goes here
      # For example: self.__elasticsearch__.search(query).records.to_a
    end
  end
end

And then while connected to the database I run the commands to create index: Model.__elasticsearch__.create_index! and after that import to these index Model.__elasticsearch__.import thats when i get the error.

It seems that elasticsearch-rails and elastiscsearch-model do not support version 8.X yet as you can check here and also here.

You got it! My bad for such mistake :sweat_smile: Thanks a lot

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.