lib/elasticsearch/api/actions/create.rb in elasticsearch-api-6.0.0 vs lib/elasticsearch/api/actions/create.rb in elasticsearch-api-6.0.1
- old
+ new
@@ -1,35 +1,42 @@
module Elasticsearch
module API
module Actions
- # Create a document.
+ # Create a new document.
#
- # Enforce the _create_ operation when indexing a document --
- # the operation will return an error when the document already exists.
+ # The API will create new document, if it doesn't exist yet -- in that case, it will return
+ # a `409` error (`version_conflict_engine_exception`).
#
- # @example Create a document
+ # You can leave out the `:id` parameter for the ID to be generated automatically
#
+ # @example Create a document with an ID
+ #
# client.create index: 'myindex',
- # type: 'mytype',
- # id: '1',
- # body: {
- # title: 'Test 1',
- # tags: ['y', 'z'],
- # published: true,
- # published_at: Time.now.utc.iso8601,
- # counter: 1
- # }
+ # type: 'doc',
+ # id: '1',
+ # body: {
+ # title: 'Test 1'
+ # }
#
- # @option (see Actions#index)
+ # @example Create a document with an auto-generated ID
#
- # (The `:op_type` argument is ignored.)
+ # client.create index: 'myindex',
+ # type: 'doc',
+ # body: {
+ # title: 'Test 1'
+ # }
#
- # @see http://elasticsearch.org/guide/reference/api/index_/
+ # @option (see Actions#index)
#
+ # @see https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html#_automatic_id_generation
+ #
def create(arguments={})
- raise ArgumentError, "Required argument 'id' missing" unless arguments[:id]
- index arguments.update :op_type => 'create'
+ if arguments[:id]
+ index arguments.update :op_type => 'create'
+ else
+ index arguments
+ end
end
end
end
end