(2). 将name更新为2,更新过程中使用seq_no=18
PUT http://192.168.56.10:9200/customer/external/1?if_seq_no=18&if_primary_term=6
结果为:(出现更新错误)
查询新的数据 GET http://192.168.56.10:9200/customer/external/1
(4). 再次更新,更新成功
PUT http://192.168.56.10:9200/customer/external/1?if_seq_no=19&if_primary_term=1
③. 更新文档
带了_update的会去检查元数据,如果更新的数据和元数据对比没有变化,则不会叠加版本
POST customer/external/1/_update { "doc":{ "name":"111" } } 或者 //不会检查元数据,它的版本号都会更新,不断的叠加版本 POST customer/external/1 { "name":"222" } 或者 PUT customer/external/1 { "name":"222" }
④. 删除文档或索引
DELETE customer/external/1 DELETE customer 注:elasticsearch并没有提供删除类型的操作,只提供了删除索引和文档的操作。 实例:删除id=1的数据,删除后继续查询 DELETE http://192.168.56.10:9200/customer/external/1 { "_index": "customer", "_type": "external", "_id": "1", "_version": 14, "result": "deleted", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_seq_no": 22, "_primary_term": 6 } 再次执行DELETE http://192.168.56.10:9200/customer/external/1 { "_index": "customer", "_type": "external", "_id": "1", "_version": 15, "result": "not_found", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_seq_no": 23, "_primary_term": 6 } GET http://192.168.56.10:9200/customer/external/1 { "_index": "customer", "_type": "external", "_id": "1", "found": false }
删除索引 实例:删除整个costomer索引数据 删除前,所有的索引http://192.168.56.10:9200/_cat/indices green open .kibana_task_manager_1 DhtDmKrsRDOUHPJm1EFVqQ 1 0 2 0 31.3kb 31.3kb green open .apm-agent-configuration vxzRbo9sQ1SvMtGkx6aAHQ 1 0 0 0 283b 283b green open .kibana_1 rdJ5pejQSKWjKxRtx-EIkQ 1 0 8 3 28.8kb 28.8kb yellow open customer mG9XiCQISPmfBAmL1BPqIw 1 1 9 1 8.6kb 8.6kb 删除“ customer ”索引 DELTE http://192.168.56.10:9200/customer 响应 { "acknowledged": true } 删除后,所有的索引http://192.168.56.10:9200/_cat/indices green open .kibana_task_manager_1 DhtDmKrsRDOUHPJm1EFVqQ 1 0 2 0 31.3kb 31.3kb green open .apm-agent-configuration vxzRbo9sQ1SvMtGkx6aAHQ 1 0 0 0 283b 283b green open .kibana_1 rdJ5pejQSKWjKxRtx-EIkQ 1 0 8 3 28.8kb 28.8kb