Sha256: d97e722c6cf2e28d62e2132f01e48afb0042ee3b34885d12a85d40aba2091d51

Contents?: true

Size: 1.17 KB

Versions: 18

Compression:

Stored size: 1.17 KB

Contents

module Elasticity
  class Bulk
    def initialize(client)
      @client     = client
      @operations = []
    end

    def index(index_name, type, id, attributes)
      @operations << { index: { _index: index_name, _type: type, _id: id, data: attributes }}
    end

    def delete(index_name, type, id)
      @operations << { delete: { _index: index_name, _type: type, _id: id }}
    end

    def execute
      @client.bulk(body: @operations)
    end

    class Index < Bulk
      def initialize(client, index_name)
        super(client)
        @index_name = index_name
      end

      def index(type, id, attributes)
        super(@index_name, type, id, attributes)
      end

      def delete(type, id)
        super(@index_name, type, id)
      end
    end

    class Alias < Bulk
      def initialize(client, update_alias, delete_indexes)
        super(client)
        @update_alias   = update_alias
        @delete_indexes = delete_indexes
      end

      def index(type, id, attributes)
        super(@update_alias, type, id, attributes)
      end

      def delete(type, id)
        @delete_indexes.each do |index|
          super(index, type, id)
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
es-elasticity-0.5.0 lib/elasticity/bulk.rb
es-elasticity-0.4.5 lib/elasticity/bulk.rb
es-elasticity-0.4.4 lib/elasticity/bulk.rb
es-elasticity-0.4.3 lib/elasticity/bulk.rb
es-elasticity-0.4.2 lib/elasticity/bulk.rb
es-elasticity-0.3.10 lib/elasticity/bulk.rb
es-elasticity-0.4.1 lib/elasticity/bulk.rb
es-elasticity-0.4.0 lib/elasticity/bulk.rb
es-elasticity-0.3.9 lib/elasticity/bulk.rb
es-elasticity-0.3.8 lib/elasticity/bulk.rb
es-elasticity-0.3.7 lib/elasticity/bulk.rb
es-elasticity-0.3.6 lib/elasticity/bulk.rb
es-elasticity-0.3.5 lib/elasticity/bulk.rb
es-elasticity-0.3.4 lib/elasticity/bulk.rb
es-elasticity-0.3.3 lib/elasticity/bulk.rb
es-elasticity-0.3.2 lib/elasticity/bulk.rb
es-elasticity-0.3.1 lib/elasticity/bulk.rb
es-elasticity-0.3.0 lib/elasticity/bulk.rb