4

I have trouble with elasticsearch-rails, when I'm using Business.__elasticsearch__.create_index! I'm getting an error:

{"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [business : {dynamic=true, properties={id={type=integer}}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [business : {dynamic=true, properties={id={type=integer}}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [business : {dynamic=true, properties={id={type=integer}}}]"}},"status":400}

Behind that request is:

PUT http://localhost:9200/development_businesses [status:400, request:0.081s, query:N/A] {"settings":{"index":{"number_of_shards":1}},"mappings":{"business":{"dynamic":"true","properties":{"id":{"type":"integer"}}}}}

My Model code:

`
after_save :reindex_model
Elasticsearch::Model.client = Elasticsearch::Client.new url: ENV['BONSAI_URL'], log: true
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks
index_name [Rails.env, model_name.collection.gsub('///', '-')].join('_')
document_type self.name.downcase
`

I have defined my mapping:

`
settings index: { number_of_shards: 1 } do
    mappings dynamic: 'true' do
        indexes :id, type: 'integer'
    end
end
`
4
  • If you are using version 7.x stackoverflow.com/questions/58629372/… Commented Dec 2, 2019 at 14:35
  • what about "dynamic":"true" ? Commented Dec 2, 2019 at 14:35
  • I tried both true and false but no effect @Sunny Commented Dec 2, 2019 at 14:38
  • @AhmadAli have a look on my given answer below Commented Dec 2, 2019 at 14:54

2 Answers 2

5

Remove the part {"business":{"dynamic":"true"}} while creating the mapping. Try like below that works fine for me-

PUT /development_businesses/
{
  "settings": {
    "index": {
      "number_of_shards": 1
    }
  },
  "mappings": {
      "properties": {
        "id": {
          "type": "integer"
        }
      }
  }
}
Sign up to request clarification or add additional context in comments.

4 Comments

I can remove dynamic: 'true', but how I can remove 'business' using rails code.
@AhmadAli brother I not familiar with ruby that's why couldn't help you here
Your answer is right @Sunny and as in my case, I removed document_type from my Model class, and now everything works fine.
@AhmadAli glad it helps you somehow :)
2

As of ES 7, mapping types have been removed. You can read more details here

If you are using Ruby On Rails this means that you may need to remove document_type from your model or concern.

As an alternative to mapping types one solution is to use an index per document type.

Before:

module Searchable
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
    index_name [Rails.env, Rails.application.class.module_parent_name.underscore].join('_')
    document_type self.name.downcase
  end
end

After:

module Searchable
  extend ActiveSupport::Concern

  included do
    include Elasticsearch::Model
    include Elasticsearch::Model::Callbacks
    index_name [Rails.env, Rails.application.class.module_parent_name.underscore, self.name.downcase].join('_')
  end
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.