Searchkick word_start 与嵌套字段匹配

Searchkick word_start match with nested field

我有一个带有 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