Sha256: 71f22608b5ac81028d0a0b1bb552103380f28c94de7e943270435c7fdaf8c60a

Contents?: true

Size: 1.07 KB

Versions: 5

Compression:

Stored size: 1.07 KB

Contents

module Elasticsearch
  module API
    module Indices
      module Actions

        # Return true if the index (or all indices in a list) exists, false otherwise.
        #
        # @example Check whether index named _myindex_ exists
        #
        #     client.indices.exists index: 'myindex'
        #
        # @option arguments [List] :index A comma-separated list of indices to check (*Required*)
        # @return [true,false]
        #
        # @see http://www.elasticsearch.org/guide/reference/api/admin-indices-indices-exists/
        #
        def exists(arguments={})
          raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
          method = 'HEAD'
          path   = Utils.__listify(arguments[:index])
          params = {}
          body   = nil

          perform_request(method, path, params, body).status == 200 ? true : false
        rescue Exception => e
          if e.class.to_s =~ /NotFound/ || e.message =~ /Not\s*Found|404/i
            false
          else
            raise e
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
elasticsearch-api-0.4.3 lib/elasticsearch/api/actions/indices/exists.rb
elasticsearch-api-0.4.2 lib/elasticsearch/api/actions/indices/exists.rb
elasticsearch-api-0.4.1 lib/elasticsearch/api/actions/indices/exists.rb
elasticsearch-api-0.4.0 lib/elasticsearch/api/actions/indices/exists.rb
elasticsearch-api-0.0.2 lib/elasticsearch/api/actions/indices/exists.rb