elasticsearch,Ruby On Rails,elasticsearch" /> elasticsearch,Ruby On Rails,elasticsearch" />

Ruby on rails 使用elasticsearch rails搜索表单pdf附件

Ruby on rails 使用elasticsearch rails搜索表单pdf附件,ruby-on-rails,elasticsearch,Ruby On Rails,elasticsearch,如何使用elasticsearch rails将pdf附件索引到elasticsearch服务器 我的密码是贝娄 module Searchable extend ActiveSupport::Concern included do include Elasticsearch::Model include Elasticsearch::Model::Callbacks __elasticsearch__.client = Elasticsearch::Client.new log: true

如何使用elasticsearch rails将pdf附件索引到elasticsearch服务器

我的密码是贝娄

module Searchable
extend ActiveSupport::Concern

included do
include Elasticsearch::Model
include Elasticsearch::Model::Callbacks

__elasticsearch__.client = Elasticsearch::Client.new log: true
__elasticsearch__.client.transport.logger.formatter = proc { |s, d, p, m| "\e[32m#{m}\n\e[0m" }

include Indexing
after_touch() { __elasticsearch__.index_document }
end

module Indexing

# Customize the JSON serialization for Elasticsearch
  def as_indexed_json(options={})
    self.as_json(
      include: {
               comments: { only: :message }
             })
           {
             name: "#{title} - #{id}",
             comments: comments,

             attachment: Base64.encode64(File.open(Rails.root.to_s + '/public' + resume.to_s) { |io| io.read }).to_json
           }
   end

 end

end
此代码仅将文件内容索引为base64_编码格式。请帮帮我