Sha256: fe9ac452654024e35811d299fccc346caf0778ceb0b2112033a7bbd94cd31de5

Contents?: true

Size: 1.19 KB

Versions: 1

Compression:

Stored size: 1.19 KB

Contents

require 'hashie/mash'

module Elasticsearch
  module Extensions
    module Documents
      class Index
        attr_reader :adapter

        def initialize(adapter = nil)
          @adapter = adapter || Documents.index_adapter
        end

        def index(document)
          payload = {
            type:   document.class.type,
            id:     document.id,
            body:   document.as_hash,
          }
          adapter.index payload
        end

        def delete(document)
          payload = {
            type:   document.class.type,
            id:     document.id,
          }
          adapter.delete payload
        rescue Elasticsearch::Transport::Transport::Errors::NotFound => not_found
          Documents.logger.info "[Documents] Attempted to delete missing document: #{not_found}"
        end

        def search(query)
          response = adapter.search(query.as_hash)
          Hashie::Mash.new(response)
        end

        def refresh
          adapter.refresh
        end

        def reindex(options = {}, &block)
          adapter.reindex(options, &block)
        end

        def bulk_index(documents)
          adapter.bulk_index(documents)
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
elasticsearch-documents-1.0.0 lib/elasticsearch/extensions/documents/index.rb