在searchkick中定义自定义映射不起作用

时间:2016-02-08 06:48:07

标签: ruby-on-rails elasticsearch searchkick

我有一个Campaign模型,这就是我的自定义映射的样子:

searchkick mappings: { 
 campaign: {
   properties: {
     title: {type: "string", analyzer: "snowball"},
     deal_title: {type: "string", analyzer: "snowball"},
     description: {type: "string", analyzer: "snowball"}
   }                                         
 }                                           
}

当我重新索引广告系列文档时,请执行

c = Campaign.search "this is"

我收到以下错误:

Searchkick::InvalidQueryError: [400] {  
   "error":{  
      "root_cause":[  
         {  
            "type":"query_parsing_exception",
            "reason":"[match] analyzer [searchkick_search] not found",
            "index":"campaigns_development_20160205130806185",
            "line":1,
            "col":96
         }
      ],
      "type":"search_phase_execution_exception",
      "reason":"all shards failed",
      "phase":"query",
      "grouped":true,
      "failed_shards":[  
         {  
            "shard":0,
            "index":"campaigns_development_20160205130806185",
            "node":"kiTXKzIEQjuI9UNDzXZ1DA",
            "reason":{  
               "type":"query_parsing_exception",
               "reason":"[match] analyzer [searchkick_search] not found",
               "index":"campaigns_development_20160205130806185",
               "line":1,
               "col":96
            }
         }
      ]
   },
   "status":400
}

当我将merge_mappings:true添加到现有映射时,

searchkick merge_mappings: true, mappings: { 
 campaign: {
   properties: {
     title: {type: "string", analyzer: "snowball"},
     deal_title: {type: "string", analyzer: "snowball"},
     description: {type: "string", analyzer: "snowball"}
   }                                         
 }                                           
}

search c = Campaign.search "this is"

,我在广告系列中得到了结果"这是"在title / deal_title / description。

但由于我使用的是雪球分析器,因此这些常用的停用词应该从未被编入索引,从而返回0结果。

此外,在映射已更改的第二个方案中,它不会出错。所以我认为searchkick没有识别雪球分析器,因为我做了merge_mappings:true,它必须使用默认分析器进行索引。这就是为什么它不会给出任何错误。

所以真正的问题是:在我展示的第一个映射中是否存在问题,或者searchkick是否识别出雪球(或任何分析器,使用停止分析器尝试相同的事情)分析器?

0 个答案:

没有答案