| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 | [[docs-delete]]== Delete APIThe delete API allows to delete a typed JSON document from a specificindex based on its id. The following example deletes the JSON documentfrom an index called twitter, under a type called tweet, with id valued1:[source,js]--------------------------------------------------$ curl -XDELETE 'http://localhost:9200/twitter/tweet/1'--------------------------------------------------The result of the above delete operation is:[source,js]--------------------------------------------------{    "found" : true,    "_index" : "twitter",    "_type" : "tweet",    "_id" : "1",    "_version" : 2}--------------------------------------------------[float][[delete-versioning]]=== VersioningEach document indexed is versioned. When deleting a document, the`version` can be specified to make sure the relevant document we aretrying to delete is actually being deleted and it has not changed in themeantime. Every write operation executed on a document, deletes included,causes its version to be incremented.[float][[delete-routing]]=== RoutingWhen indexing using the ability to control the routing, in order todelete a document, the routing value should also be provided. Forexample:[source,js]--------------------------------------------------$ curl -XDELETE 'http://localhost:9200/twitter/tweet/1?routing=kimchy'--------------------------------------------------The above will delete a tweet with id 1, but will be routed based on theuser. Note, issuing a delete without the correct routing, will cause thedocument to not be deleted.Many times, the routing value is not known when deleting a document. Forthose cases, when specifying the `_routing` mapping as `required`, andno routing value is specified, the delete will be broadcastedautomatically to all shards.[float][[delete-parent]]=== ParentThe `parent` parameter can be set, which will basically be the same assetting the routing parameter.Note that deleting a parent document does not automatically delete itschildren. One way of deleting all child documents given a parent's id isto perform a <<docs-delete-by-query,delete by query>> on the childindex with the automatically generated (and indexed)field _parent, which is in the format parent_type#parent_id.[float][[delete-index-creation]]=== Automatic index creationThe delete operation automatically creates an index if it has not beencreated before (check out the <<indices-create-index,create index API>>for manually creating an index), and also automatically creates adynamic type mapping for the specific type if it has not been createdbefore (check out the <<indices-put-mapping,put mapping>>API for manually creating type mapping).[float][[delete-distributed]]=== DistributedThe delete operation gets hashed into a specific shard id. It then getsredirected into the primary shard within that id group, and replicated(if needed) to shard replicas within that id group.[float][[delete-replication]]=== Replication TypeThe replication of the operation can be done in an asynchronous mannerto the replicas (the operation will return once it has be executed onthe primary shard). The `replication` parameter can be set to `async`(defaults to `sync`) in order to enable it.[float][[delete-consistency]]=== Write ConsistencyControl if the operation will be allowed to execute based on the numberof active shards within that partition (replication group). The valuesallowed are `one`, `quorum`, and `all`. The parameter to set it is`consistency`, and it defaults to the node level setting of`action.write_consistency` which in turn defaults to `quorum`.For example, in a N shards with 2 replicas index, there will have to beat least 2 active shards within the relevant partition (`quorum`) forthe operation to succeed. In a N shards with 1 replica scenario, therewill need to be a single shard active (in this case, `one` and `quorum`is the same).[float][[delete-refresh]]=== RefreshThe `refresh` parameter can be set to `true` in order to refresh the relevantprimary and replica shards after the delete operation has occurred and make itsearchable. Setting it to `true` should be done after careful thought andverification that this does not cause a heavy load on the system (and slowsdown indexing).[float][[delete-timeout]]=== TimeoutThe primary shard assigned to perform the delete operation might not beavailable when the delete operation is executed. Some reasons for thismight be that the primary shard is currently recovering from a gatewayor undergoing relocation. By default, the delete operation will wait onthe primary shard to become available for up to 1 minute before failingand responding with an error. The `timeout` parameter can be used toexplicitly specify how long it waits. Here is an example of setting itto 5 minutes:[source,js]--------------------------------------------------$ curl -XDELETE 'http://localhost:9200/twitter/tweet/1?timeout=5m'--------------------------------------------------
 |