ruby-on-railselasticsearchelasticsearch-railselasticsearch-model

Rails __elasticsearch__.create_index! "Root mapping definition has unsupported parameters(mapper_parsing_exception)"


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
`

Solution

  • 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"
            }
          }
      }
    }