delete.asciidoc 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. [[docs-delete]]
  2. == Delete API
  3. The delete API allows to delete a typed JSON document from a specific
  4. index based on its id. The following example deletes the JSON document
  5. from an index called twitter, under a type called tweet, with id valued
  6. 1:
  7. [source,js]
  8. --------------------------------------------------
  9. $ curl -XDELETE 'http://localhost:9200/twitter/tweet/1'
  10. --------------------------------------------------
  11. The result of the above delete operation is:
  12. [source,js]
  13. --------------------------------------------------
  14. {
  15. "found" : true,
  16. "_index" : "twitter",
  17. "_type" : "tweet",
  18. "_id" : "1",
  19. "_version" : 2
  20. }
  21. --------------------------------------------------
  22. [float]
  23. [[delete-versioning]]
  24. === Versioning
  25. Each document indexed is versioned. When deleting a document, the
  26. `version` can be specified to make sure the relevant document we are
  27. trying to delete is actually being deleted and it has not changed in the
  28. meantime. Every write operation executed on a document, deletes included,
  29. causes its version to be incremented.
  30. [float]
  31. [[delete-routing]]
  32. === Routing
  33. When indexing using the ability to control the routing, in order to
  34. delete a document, the routing value should also be provided. For
  35. example:
  36. [source,js]
  37. --------------------------------------------------
  38. $ curl -XDELETE 'http://localhost:9200/twitter/tweet/1?routing=kimchy'
  39. --------------------------------------------------
  40. The above will delete a tweet with id 1, but will be routed based on the
  41. user. Note, issuing a delete without the correct routing, will cause the
  42. document to not be deleted.
  43. Many times, the routing value is not known when deleting a document. For
  44. those cases, when specifying the `_routing` mapping as `required`, and
  45. no routing value is specified, the delete will be broadcasted
  46. automatically to all shards.
  47. [float]
  48. [[delete-parent]]
  49. === Parent
  50. The `parent` parameter can be set, which will basically be the same as
  51. setting the routing parameter.
  52. Note that deleting a parent document does not automatically delete its
  53. children. One way of deleting all child documents given a parent's id is
  54. to perform a <<docs-delete-by-query,delete by query>> on the child
  55. index with the automatically generated (and indexed)
  56. field _parent, which is in the format parent_type#parent_id.
  57. [float]
  58. [[delete-index-creation]]
  59. === Automatic index creation
  60. The delete operation automatically creates an index if it has not been
  61. created before (check out the <<indices-create-index,create index API>>
  62. for manually creating an index), and also automatically creates a
  63. dynamic type mapping for the specific type if it has not been created
  64. before (check out the <<indices-put-mapping,put mapping>>
  65. API for manually creating type mapping).
  66. [float]
  67. [[delete-distributed]]
  68. === Distributed
  69. The delete operation gets hashed into a specific shard id. It then gets
  70. redirected into the primary shard within that id group, and replicated
  71. (if needed) to shard replicas within that id group.
  72. [float]
  73. [[delete-replication]]
  74. === Replication Type
  75. The replication of the operation can be done in an asynchronous manner
  76. to the replicas (the operation will return once it has be executed on
  77. the primary shard). The `replication` parameter can be set to `async`
  78. (defaults to `sync`) in order to enable it.
  79. [float]
  80. [[delete-consistency]]
  81. === Write Consistency
  82. Control if the operation will be allowed to execute based on the number
  83. of active shards within that partition (replication group). The values
  84. allowed are `one`, `quorum`, and `all`. The parameter to set it is
  85. `consistency`, and it defaults to the node level setting of
  86. `action.write_consistency` which in turn defaults to `quorum`.
  87. For example, in a N shards with 2 replicas index, there will have to be
  88. at least 2 active shards within the relevant partition (`quorum`) for
  89. the operation to succeed. In a N shards with 1 replica scenario, there
  90. will need to be a single shard active (in this case, `one` and `quorum`
  91. is the same).
  92. [float]
  93. [[delete-refresh]]
  94. === Refresh
  95. The `refresh` parameter can be set to `true` in order to refresh the relevant
  96. primary and replica shards after the delete operation has occurred and make it
  97. searchable. Setting it to `true` should be done after careful thought and
  98. verification that this does not cause a heavy load on the system (and slows
  99. down indexing).
  100. [float]
  101. [[delete-timeout]]
  102. === Timeout
  103. The primary shard assigned to perform the delete operation might not be
  104. available when the delete operation is executed. Some reasons for this
  105. might be that the primary shard is currently recovering from a gateway
  106. or undergoing relocation. By default, the delete operation will wait on
  107. the primary shard to become available for up to 1 minute before failing
  108. and responding with an error. The `timeout` parameter can be used to
  109. explicitly specify how long it waits. Here is an example of setting it
  110. to 5 minutes:
  111. [source,js]
  112. --------------------------------------------------
  113. $ curl -XDELETE 'http://localhost:9200/twitter/tweet/1?timeout=5m'
  114. --------------------------------------------------