gpt4 book ai didi

ruby-on-rails - Searchkick word_start与嵌套字段匹配

转载 作者:行者123 更新时间:2023-12-03 00:49:52 26 4
gpt4 key购买 nike

我有一个带有searchkick gem的Rails应用程序。我的模型有一个嵌套的JSON字段。我尝试通过word_start匹配使其可搜索。当我明确设置为:

class Post < ApplicationRecord 
searchkick word_start: [:nested_data_field]
end

我无法工作,并且出现错误:
{"type"=>"mapper_parsing_exception", "reason"=>"failed to parse [nested_data_field]", "caused_by"=>{"type"=>"illegal_state_exception", "reason"=>"Can't get text on a START_OBJECT at 1:401"}} on item with id '2596'

如何使此嵌套JSON字段匹配word_start?

我在 https://github.com/ankane/searchkick/issues/1149中发现了相同的问题-但没有结果。

最佳答案

在这种情况下,您必须明确定义字段在Elasticsearch中的索引方式

class Post < ApplicationRecord 
searchkick word_start: [:author_name, author_country]

def search_data # override indexing fields
{
tite: self.title,
date: self.created_at,
author_name: author[:name], # nested json(author field)
author_country: author[:country],
comments_ids: comments.map(&:id) # index as an array of ids
}
end
end

关于ruby-on-rails - Searchkick word_start与嵌套字段匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55430115/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com