Method: Elasticsearch::API::Actions#exists

Defined in:
lib/elasticsearch/api/actions/exists.rb

#exists(arguments = {}) ⇒ Object Also known as: exists?

Returns information about whether a document exists in an index.

*Deprecation notice*: Specifying types in urls has been deprecated Deprecated since version 7.0.0

Parameters:

  • arguments (Hash) (defaults to: {})

    a customizable set of options

Options Hash (arguments):

  • :id (String)

    The document ID

  • :index (String)

    The name of the index

  • :type (String)

    The type of the document (use ‘_all` to fetch the first document matching the ID across all types) Deprecated

  • :stored_fields (List)

    A comma-separated list of stored fields to return in the response

  • :preference (String)

    Specify the node or shard the operation should be performed on (default: random)

  • :realtime (Boolean)

    Specify whether to perform the operation in realtime or search mode

  • :refresh (Boolean)

    Refresh the shard containing the document before performing the operation

  • :routing (String)

    Specific routing value

  • :_source (List)

    True or false to return the _source field or not, or a list of fields to return

  • :_source_excludes (List)

    A list of fields to exclude from the returned _source field

  • :_source_includes (List)

    A list of fields to extract and return from the _source field

  • :version (Number)

    Explicit version number for concurrency control

  • :version_type (String)

    Specific version type (options: internal, external, external_gte, force)

  • :headers (Hash)

    Custom HTTP headers

Raises:

  • (ArgumentError)

See Also:



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/elasticsearch/api/actions/exists.rb', line 45

def exists(arguments = {})
  raise ArgumentError, "Required argument 'index' missing" unless arguments[:index]
  raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]

  headers = arguments.delete(:headers) || {}

  arguments = arguments.clone

  _id = arguments.delete(:id)

  _index = arguments.delete(:index)

  _type = arguments.delete(:type)

  method = Elasticsearch::API::HTTP_HEAD
  path   = if _index && _type && _id
             "#{Utils.__listify(_index)}/#{Utils.__listify(_type)}/#{Utils.__listify(_id)}"
           else
             "#{Utils.__listify(_index)}/_doc/#{Utils.__listify(_id)}"
           end
  params = Utils.__validate_and_extract_params arguments, ParamsRegistry.get(__method__)

  body = nil

  Utils.__rescue_from_not_found do
    perform_request(method, path, params, body, headers).status == 200 ? true : false
  end
end