首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >升级后无法将索引映射到模型。

升级后无法将索引映射到模型。
EN

Stack Overflow用户
提问于 2020-09-22 04:36:20
回答 1查看 496关注 0票数 1

工作:环境:

  • Rails 4.1
  • Search腿2.3.2

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

代码语言:javascript
运行
复制
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看起来像:

代码语言:javascript
运行
复制
=> [
{"_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}
]

一切都如期而至。我在搜索框中输入我的术语,然后得到我的结果。

代码语言:javascript
运行
复制
res.first
 => #<Customer id: 162, field: yada-yada>

升级为:

5.2

  • Searchkick
  • Rails 4.4.1

我做同样的查询,我得到以下回击

res.hits:

代码语言:javascript
运行
复制
[
{"_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'

下面是我在模型中的设置:

代码语言:javascript
运行
复制
include Elasticsearch::Model <-- Added after upgrade
include Elasticsearch::Model::Callbacks <-- Added after upgrade
searchkick match: :word_start, searchable: [:name]
scope :search_import, -> {includes(:user)}

我能帮你找出为什么会发生这种事吗?

代码语言:javascript
运行
复制
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'

谢谢

EN

Stack Overflow用户

发布于 2020-09-23 01:31:18

我发现了问题。

在文档中:

多个模型在多个模型之间搜索,其中:

Searchkick.search“牛奶”,型号:产品,类别

因此,改变:

代码语言:javascript
运行
复制
index_name: [Customer.searchkick_index.name, User.searchkick_index.name]

代码语言:javascript
运行
复制
models: [Customer, User]

解决了我的问题。

票数 4
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64003141

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档