Rails 5.1 与 ElasticSearch 7.1 重建索引错误

Rails 5.1 with ElasticSearch 7.1 reindex error

我在 运行 Rails 5 console.

上执行此命令时遇到一些问题
:017 > User.reindex

我在用户中有一些数据table

 :012 >   User.all
  User Load (10.3ms)  SELECT  "users".* FROM "users" LIMIT   [["LIMIT", 11]]
 => #<ActiveRecord::Relation [#<User id: 1, email: "test@gmai.com", first_name: "test", last_name: "test", parent_id: nil, created_at: "2019-06-17 05:50:15", updated_at: "2019-06-17 09:27:56", role: "pm_lead", is_approved: true, phone: nil, country_code: nil, initials: nil, theme_code: "#4fa399", profile_pic: nil, is_guest: false, guest_migrated: false, projects_count: 0, is_archived: false, office: nil, department: nil, designation: nil, partner_id: 1>]> 

elasticSearch 错误:

Elasticsearch::Transport::Transport::Errors::BadRequest: [400] {"error":{"root_cause":[{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters:  [user : {_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={name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}, last_name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}, first_name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}}}]"}],"type":"mapper_parsing_exception","reason":"Failed to parse mapping [_doc]: Root mapping definition has unsupported parameters:  [user : {_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={name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}, last_name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}, first_name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}}}]","caused_by":{"type":"mapper_parsing_exception","reason":"Root mapping definition has unsupported parameters:  [user : {_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={name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}, last_name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}, first_name={ignore_above=30000, type=keyword, fields={analyzed={analyzer=searchkick_index, index=true, type=text}, text_middle={analyzer=searchkick_text_middle_index, index=true, type=text}}}}}]"}},"status":400}

我找到了问题的解决方案。只需更新 searchkick gem 版本 3.1 至 4.01。

-    searchkick (3.1.0)
-      activemodel (>= 4.2)
-      elasticsearch (>= 5)
+    searchkick (4.0.2)
+      activemodel (>= 5)
+      elasticsearch (>= 6)

gem 'searchkick', '~> 4.01' 使用 elasticseatch 7.x

gem 'searchkick', '~> 3.1', '>= 3.1.2' 这适用于 elasticseatch 6.x