Rails 模型中定义的 Elasticsearch 分析器映射未在 elasticsearch 中报告

Rails Elasticsearch analyzer mappings defined in model are not reported in elasticsearch

在我的 Recipe 模型中我有:

class Recipe < ActiveRecord::Base

index_name "recipes-#{Rails.env}"

settings do
  mappings dynamic: 'false' do
    indexes :title, type: 'string', analyzer: 'french'
    indexes :description, type: 'string', analyzer: 'french'
  end
end

def as_indexed_json(options={})
  self.as_json({only: [:title, :description]})
end

然后在 rails 控制台中,我启动 Recipe.import。当通过 curl 或 Sense GET /recipes-development/_mapping/ 询问 elasticsearch 时,我得到

{
   "recipes-development": {
      "mappings": {
         "recipe": {
            "properties": {
               "description": {
                  "type": "string"
               },
               "title": {
                  "type": "string"
               }
            }
         }
      }
   }
}

我丢失了有关分析器的所有信息。任何想法将不胜感激

Recipe.import之前你必须执行

Recipe.__elasticsearch__.create_index! force: true