delete.asciidoc 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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. "_shards" : {
  16. "total" : 10,
  17. "failed" : 0,
  18. "successful" : 10
  19. },
  20. "found" : true,
  21. "_index" : "twitter",
  22. "_type" : "tweet",
  23. "_id" : "1",
  24. "_version" : 2,
  25. "result": "deleted"
  26. }
  27. --------------------------------------------------
  28. [float]
  29. [[delete-versioning]]
  30. === Versioning
  31. Each document indexed is versioned. When deleting a document, the
  32. `version` can be specified to make sure the relevant document we are
  33. trying to delete is actually being deleted and it has not changed in the
  34. meantime. Every write operation executed on a document, deletes included,
  35. causes its version to be incremented.
  36. [float]
  37. [[delete-routing]]
  38. === Routing
  39. When indexing using the ability to control the routing, in order to
  40. delete a document, the routing value should also be provided. For
  41. example:
  42. [source,js]
  43. --------------------------------------------------
  44. $ curl -XDELETE 'http://localhost:9200/twitter/tweet/1?routing=kimchy'
  45. --------------------------------------------------
  46. The above will delete a tweet with id 1, but will be routed based on the
  47. user. Note, issuing a delete without the correct routing, will cause the
  48. document to not be deleted.
  49. When the `_routing` mapping is set as `required` and no routing value is
  50. specified, the delete api will throw a `RoutingMissingException` and reject
  51. the request.
  52. [float]
  53. [[delete-parent]]
  54. === Parent
  55. The `parent` parameter can be set, which will basically be the same as
  56. setting the routing parameter.
  57. Note that deleting a parent document does not automatically delete its
  58. children. One way of deleting all child documents given a parent's id is
  59. to use the <<docs-delete-by-query,Delete By Query API>> to perform a
  60. index with the automatically generated (and indexed)
  61. field _parent, which is in the format parent_type#parent_id.
  62. When deleting a child document its parent id must be specified, otherwise
  63. the delete request will be rejected and a `RoutingMissingException` will be
  64. thrown instead.
  65. [float]
  66. [[delete-index-creation]]
  67. === Automatic index creation
  68. The delete operation automatically creates an index if it has not been
  69. created before (check out the <<indices-create-index,create index API>>
  70. for manually creating an index), and also automatically creates a
  71. dynamic type mapping for the specific type if it has not been created
  72. before (check out the <<indices-put-mapping,put mapping>>
  73. API for manually creating type mapping).
  74. [float]
  75. [[delete-distributed]]
  76. === Distributed
  77. The delete operation gets hashed into a specific shard id. It then gets
  78. redirected into the primary shard within that id group, and replicated
  79. (if needed) to shard replicas within that id group.
  80. [float]
  81. [[delete-wait-for-active-shards]]
  82. === Wait For Active Shards
  83. When making delete requests, you can set the `wait_for_active_shards`
  84. parameter to require a minimum number of shard copies to be active
  85. before starting to process the delete request. See
  86. <<index-wait-for-active-shards,here>> for further details and a usage
  87. example.
  88. [float]
  89. [[delete-refresh]]
  90. === Refresh
  91. Control when the changes made by this request are visible to search. See
  92. <<docs-refresh>>.
  93. [float]
  94. [[delete-timeout]]
  95. === Timeout
  96. The primary shard assigned to perform the delete operation might not be
  97. available when the delete operation is executed. Some reasons for this
  98. might be that the primary shard is currently recovering from a store
  99. or undergoing relocation. By default, the delete operation will wait on
  100. the primary shard to become available for up to 1 minute before failing
  101. and responding with an error. The `timeout` parameter can be used to
  102. explicitly specify how long it waits. Here is an example of setting it
  103. to 5 minutes:
  104. [source,js]
  105. --------------------------------------------------
  106. $ curl -XDELETE 'http://localhost:9200/twitter/tweet/1?timeout=5m'
  107. --------------------------------------------------