【问题标题】:Searchkick word_start match with nested fieldSearchkick word_start 与嵌套字段匹配
【发布时间】:2019-08-21 03:26:34
【问题描述】:

我有一个带有 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 发现了同样的问题 - 但没有结果。

【问题讨论】:

    标签: ruby-on-rails elasticsearch searchkick


    【解决方案1】:

    在这种情况下,您必须明确定义字段在 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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-03
      • 1970-01-01
      相关资源
      最近更新 更多