Searchkick / Elasticsearch-根映射定义具有不受支持的参数

时间:2019-11-14 14:56:54

标签: ruby-on-rails elasticsearch searchkick heroku-api bonsai-elasticsearch

我在Heroku上有一个Rails API,并且在重新索引类时遇到以下问题。

$ heroku run rake searchkick:reindex CLASS=User

并出现以下错误

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [_default_ : {_routing={}, dynamic_templates=[{string_template={mapping={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}}}, match_mapping_type=string, match=*}}], properties={}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters: [_default_ : {_routing={}, dynamic_templates=[{string_template={mapping={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}}}, match_mapping_type=string, match=*}}], properties={}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters: [_default_ : {_routing={}, dynamic_templates=[{string_template={mapping={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}}}, match_mapping_type=string, match=*}}], properties={}}]"}},"status":400}

我的用户类别具有以下内容

class User < ApplicationRecord
    searchkick settings: { 
        number_of_shards: 1,
        number_of_replicas: 1,
        max_ngram_diff: 49,
        max_shingle_diff: 4
        }
end

我要添加max_ngram_diff和max_shingle_diff,因为这可以解决另一个问题。但是,我也不确定max_ngram_diff和max_shingle_diff的值是否正确。

来自我的Gemfile.lock

searchkick (2.5.0)
      activemodel (>= 4.1)
      elasticsearch (>= 1)
      hashie

elasticsearch (6.2.0)
      elasticsearch-api (= 6.2.0)
      elasticsearch-transport (= 6.2.0)
    elasticsearch-api (6.2.0)
      multi_json
    elasticsearch-transport (6.2.0)
      faraday
      multi_json

请问该怎么办?

1 个答案:

答案 0 :(得分:0)

此错误是由于与ElasticSearch的版本不兼容所致。即最新版本的Searchkick(即v4.1)需要ElasticSearch v7.4.0

我遇到此错误,并通过将我的Elasticsearch从7.x降级到6.8.4来解决。是runninng SearchKick(3.1.2)。

要在您的计算机上检查ElasticSearch的版本,请运行以下命令:

curl -XGET 'localhost:9200'

通过Gemfile检查计算机上运行的searchkick版本。从您的gemfile中,您需要ElasticSearch v6.2.0 要安装特定版本的ElasticSearch,请运行以下命令

brew install elasticsearch@6.2.0

重新启动您的Elasticsearch服务!