Elasticsearch 单文档 API的使用之三(删除文档)

示例:

DELETE /spring-elasticsearch-demo/person/1 HTTP/1.1
Host: localhost:9200
Content-Type: application/json
cache-control: no-cache
Postman-Token: 320dabe7-6fd8-4ba0-b6ec-50a914b29dc6

{
    "_index": "spring-elasticsearch-demo",
    "_type": "person",
    "_id": "1",
    "_version": 5,
    "result": "deleted",
    "_shards": {
        "total": 2,
        "successful": 2,
        "failed": 0
    },
    "_seq_no": 4,
    "_primary_term": 1
}
DELETE /spring-elasticsearch-demo/person/6 HTTP/1.1
Host: localhost:9200
Content-Type: application/json
cache-control: no-cache
Postman-Token: 460a2266-0a43-4498-af58-5f523f134bfa

{
    "_index": "spring-elasticsearch-demo",
    "_type": "person",
    "_id": "6",
    "_version": 1,
    "result": "not_found",
    "_shards": {
        "total": 2,
        "successful": 2,
        "failed": 0
    },
    "_seq_no": 1,
    "_primary_term": 1
}

1.version

可以指定要删除的文档版本:

DELETE /spring-elasticsearch-demo/person/2?version=4 HTTP/1.1
Host: localhost:9200
Content-Type: application/json
cache-control: no-cache
Postman-Token: 5765e4e6-75b8-425c-8510-e42cc47a74e4

{
    "error": {
        "root_cause": [
            {
                "type": "version_conflict_engine_exception",
                "reason": "[person][2]: version conflict, current version [1] is different than the one provided [4]",
                "index_uuid": "6tdQkxFpQgi9s-yXTVZpEw",
                "shard": "2",
                "index": "spring-elasticsearch-demo"
            }
        ],
        "type": "version_conflict_engine_exception",
        "reason": "[person][2]: version conflict, current version [1] is different than the one provided [4]",
        "index_uuid": "6tdQkxFpQgi9s-yXTVZpEw",
        "shard": "2",
        "index": "spring-elasticsearch-demo"
    },
    "status": 409
}

 

你可能感兴趣的:(elasticsearch,elasticsearch)