Delete document

Introduced 1.0

If you no longer need a document in your index, you can use the delete document API operation to delete it.

Example

  1. DELETE /sample-index1/_doc/1

copy

Path and HTTP methods

  1. DELETE /<index>/_doc/<_id>

URL parameters

ParameterTypeDescriptionRequired
<index>StringThe index to delete from.Yes
<_id>StringThe ID of the document to delete.Yes
if_seq_noIntegerOnly perform the delete operation if the document’s version number matches the specified number.No
if_primary_termIntegerOnly perform the delete operation if the document has the specified primary term.No
refreshEnumIf true, OpenSearch refreshes shards to make the delete operation available to search results. Valid options are true, false, and wait_for, which tells OpenSearch to wait for a refresh before executing the operation. Default is false.No
routingStringValue used to route the operation to a specific shard.No
timeoutTimeHow long to wait for a response from the cluster. Default is 1m.No
versionIntegerThe version of the document to delete, which must match the last updated version of the document.No
version_typeEnumRetrieves a specifically typed document. Available options are external (retrieve the document if the specified version number is greater than the document’s current version) and external_gte (retrieve the document if the specified version number is greater than or equal to the document’s current version). For example, to delete version 3 of a document, use /_doc/1?version=3&version_type=external.No
wait_for_active_shardsStringThe number of active shards that must be available before OpenSearch processes the delete request. Default is 1 (only the primary shard). Set to all or a positive integer. Values greater than 1 require replicas. For example, if you specify a value of 3, the index must have two replicas distributed across two additional nodes for the operation to succeed.No

Response

  1. {
  2. "_index": "sample-index1",
  3. "_id": "1",
  4. "_version": 2,
  5. "result": "deleted",
  6. "_shards": {
  7. "total": 2,
  8. "successful": 2,
  9. "failed": 0
  10. },
  11. "_seq_no": 1,
  12. "_primary_term": 15
  13. }

Response body fields

FieldDescription
_indexThe name of the index.
_idThe document’s ID.
_versionThe document’s version.
_resultThe result of the delete operation.
_shardsDetailed information about the cluster’s shards.
totalThe total number of shards.
successfulThe number of shards OpenSearch successfully deleted the document from.
failedThe number of shards OpenSearch failed to delete the document from.
_seq_noThe sequence number assigned when the document was indexed.
_primary_termThe primary term assigned when the document was indexed.

Delete document - 图1