【问题标题】:Rails __elasticsearch__.create_index! "Root mapping definition has unsupported parameters(mapper_parsing_exception)"Rails __elasticsearch__.create_index! “根映射定义具有不受支持的参数(mapper_parsing_exception)”
【发布时间】:2019-12-02 14:31:19
【问题描述】:

我在使用 elasticsearch-rails 时遇到问题,当我使用 Business.__elasticsearch__.create_index! 时出现错误:

{"error":{"root_cause":[{"type":"mapper_parsing_exception","re​​ason":"根映射定义有不支持的参数:[business : {dynamic=true, properties={id={type =integer}}}]"}],"type":"mapper_parsing_exception","re​​ason":"无法解析映射 [_doc]:根映射定义具有不受支持的参数:[business : {dynamic=true, properties={id ={type=integer}}}]","caused_by":{"type":"mapper_parsing_exception","re​​ason":"根映射定义有不受支持的参数:[business : {dynamic=true, properties={id={ type=integer}}}]"}},"status":400}

请求的背后是:

PUT http://localhost:9200/development_businesses [状态:400,请求:0.081s,查询:N/A] {"settings":{"index":{"number_of_shards":1}},"mappings":{"business":{"dynamic":"true","properties":{"id":{"type" :"整数"}}}}}

我的型号代码:

`
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
`

我已经定义了我的映射:

`
settings index: { number_of_shards: 1 } do
    mappings dynamic: 'true' do
        indexes :id, type: 'integer'
    end
end
`

【问题讨论】:

标签: ruby-on-rails elasticsearch elasticsearch-rails elasticsearch-model


【解决方案1】:

在创建映射时删除{"business":{"dynamic":"true"}} 部分。试试下面这对我来说很好 -

PUT /development_businesses/
{
  "settings": {
    "index": {
      "number_of_shards": 1
    }
  },
  "mappings": {
      "properties": {
        "id": {
          "type": "integer"
        }
      }
  }
}

【讨论】:

  • 我可以删除 dynamic: 'true',但是如何使用 rails 代码删除 'business'。
  • @AhmadAli 兄弟,我对 ruby​​ 不熟悉,所以在这里帮不了你
  • 你的答案是正确的@Sunny,就我而言,我从我的模型类中删除了 document_type,现在一切正常。
  • @AhmadAli 很高兴它能以某种方式帮助你:)
【解决方案2】:

从 ES 7 开始,映射类型已被删除。您可以阅读更多详情here

如果您使用的是 Ruby On Rails,这意味着您可能需要从您的模型或关注点中删除 document_type

作为映射类型的替代方案,一种解决方案是为每个文档类型使用一个索引。

之前:

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

之后:

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

【讨论】:

    猜你喜欢
    • 2018-01-08
    • 1970-01-01
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多