How to use highlight for elasticsearch-mapper-attachments via tire?

Tag: elasticsearch , attachment , tire Author: cat01 Date: 2013-12-30

When I tried using elasticsearch-mapper-attachments and use highlight as below the returned hightlights are still base64 encoded and not plain text. What am I missing?

class Article < ActiveRecord::Base
  include Tire::Model::Search

  has_attached_file :attachment

  mapping do
      indexes :attachment, type: 'attachment',
        fields: {
                file: {index: "no"},
                title: {store: "yes"},
                date: {store: "yes"},
                author: {analyzer: "snowball"},
                keywords: {store: "yes"},
                content_type: {store: "yes"},
                content_length: {store: "yes"}
            }
  end

  def to_indexed_json
    {
        attachment: Base64.encode64(File.open(attachment.path) { |io| io.read })
    }.to_json
  end

  def self.search(params)
    tire.search do
      query do
        if params[:q].present?
          boolean {should { string "*#{params[:q]}*"}}
        else
          all
        end
      end
      highlight :attachment, tag: false
    end
  end
end