Sha256: 7a972fe18ac12eb1be218802884da7c3c1310cfc093fd75667d48d08f94de758

Contents?: true

Size: 1.52 KB

Versions: 31

Compression:

Stored size: 1.52 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 update(index_name, type, id, attributes)
      @operations << { update: { _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 update(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 update(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

31 entries across 31 versions & 1 rubygems

Version Path
es-elasticity-0.14.1 lib/elasticity/bulk.rb
es-elasticity-0.14.0 lib/elasticity/bulk.rb
es-elasticity-0.14.0.jhumphreys lib/elasticity/bulk.rb
es-elasticity-0.13.5 lib/elasticity/bulk.rb
es-elasticity-0.13.5.dblackmon.1 lib/elasticity/bulk.rb
es-elasticity-0.13.4 lib/elasticity/bulk.rb
es-elasticity-0.13.4.zpesic lib/elasticity/bulk.rb
es-elasticity-0.13.4.dblackmon.1 lib/elasticity/bulk.rb
es-elasticity-0.13.4.dblackmon.0 lib/elasticity/bulk.rb
es-elasticity-0.13.4.dblackmon lib/elasticity/bulk.rb
es-elasticity-0.13.3 lib/elasticity/bulk.rb
es-elasticity-0.13.3.pre1 lib/elasticity/bulk.rb
es-elasticity-0.12.0 lib/elasticity/bulk.rb
es-elasticity-0.11.5 lib/elasticity/bulk.rb
es-elasticity-0.11.1 lib/elasticity/bulk.rb
es-elasticity-0.9.0 lib/elasticity/bulk.rb
es-elasticity-0.8.4 lib/elasticity/bulk.rb
es-elasticity-0.8.3 lib/elasticity/bulk.rb
es-elasticity-0.8.2 lib/elasticity/bulk.rb
es-elasticity-0.8.1 lib/elasticity/bulk.rb