Reputation: 168
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
`
Upvotes: 4
Views: 1617
Reputation: 4350
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
Upvotes: 2
Reputation: 38502
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"
}
}
}
}
Upvotes: 5