【问题标题】:Searchkick is not able to map the index to the model after upgrade升级后 Searchkick 无法将索引映射到模型
【发布时间】:2021-01-08 04:33:47
【问题描述】:

工作: 环境:

  • Rails 4.1
  • Searchkick 2.3.2

我将在控制台中执行以下查询:

res = Searchkick.search(
        "Thom",
        index_name: [Customer.searchkick_index.name, User.searchkick_index.name],
        match: :word_start,
        fields: [:first_name, :last_name, :name],
        limit: 10,
        #load: false,
        misspellings: {below: 3}
        )

res.hits 看起来像:

=> [
{"_index"=>"customers_production_20180830135206573", "_type"=>"customer", "_id"=>"162", "_score"=>66.72488}, 
{"_index"=>"customers_production_20180830135206573", "_type"=>"customer", "_id"=>"547", "_score"=>63.447693}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"447", "_score"=>59.895348}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"412", "_score"=>58.541008}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"338", "_score"=>57.721336}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"271", "_score"=>42.91793}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"315", "_score"=>42.91793}, 
{"_index"=>"users_production_20170616114857320", "_type"=>"user", "_id"=>"201", "_score"=>42.91793}
]

一切都按预期进行。我在搜索框中输入我的字词,然后我得到了结果。

res.first
 => #<Customer id: 162, field: yada-yada>

升级后:

  • Rails 5.2
  • Searchkick 4.4.1

我做同样的查询,我得到了以下命中

res.hits:

[
{"_index"=>"customers_staging_20200920170910290", "_type"=>"_doc", "_id"=>"162", "_score"=>83.6008},       
{"_index"=>"customers_staging_20200920170910290", "_type"=>"_doc", "_id"=>"547", "_score"=>79.819855},       
{"_index"=>"users_staging_20200920175208885", "_type"=>"_doc", "_id"=>"412", "_score"=>79.099915},       
{"_index"=>"users_staging_20200920175208885", "_type"=>"_doc", "_id"=>"201", "_score"=>67.04228},       
{"_index"=>"users_staging_20200920175208885", "_type"=>"_doc", "_id"=>"315", "_score"=>67.04228},       
{"_index"=>"users_staging_20200920175208885", "_type"=>"_doc", "_id"=>"338", "_score"=>67.04228}
]

res.first
Searchkick::Error: Unknown model for index: customers_staging_20200920170910290
from /home/deploy/.rvm/gems/ruby-2.6.5/gems/searchkick-4.4.1/lib/searchkick/results.rb:37:in `block in with_hit'

这是我在模型中的设置:

include Elasticsearch::Model <-- Added after upgrade
include Elasticsearch::Model::Callbacks <-- Added after upgrade
searchkick match: :word_start, searchable: [:name]
scope :search_import, -> {includes(:user)}

我能否得到任何帮助来确定发生这种情况的原因?

Searchkick::Error: Unknown model for index: customers_staging_20200920170910290
from /home/deploy/.rvm/gems/ruby-2.6.5/gems/searchkick-4.4.1/lib/searchkick/results.rb:37:in `block in with_hit'

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby elasticsearch ruby-on-rails-5 searchkick


    【解决方案1】:

    我发现了问题。

    在文档中:

    多个模型 搜索多个模型:

    Searchkick.search "milk",型号:[产品,类别]

    如此变化:

    index_name: [Customer.searchkick_index.name, User.searchkick_index.name]
    

    models: [Customer, User]
    

    解决了我的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多