当前位置: 代码迷 >> 综合 >> Elastic Search 7.2 删除数据
  详细解决方案

Elastic Search 7.2 删除数据

热度:45   发布时间:2023-12-14 03:45:31.0
@Autowired
private RestHighLevelClient client;
/*** 根据索引删除*/
public boolean deleteIndex(String indexName) {boolean acknowledged = false;try {DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest(indexName);deleteIndexRequest.indicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);AcknowledgedResponse delete = client.indices().delete(deleteIndexRequest, RequestOptions.DEFAULT);acknowledged = delete.isAcknowledged();} catch (IOException e) {e.printStackTrace();}return acknowledged;
}/**
* 根据索引和id删除
* @param index
* @param type "_doc"
* @param id
*/
public void deleteById(String index, String type, String id) {DeleteRequest deleteRequest = new DeleteRequest(index, type,id);DeleteResponse response = null;try {response = client.delete(deleteRequest,RequestOptions.DEFAULT);} catch (IOException e) {e.printStackTrace();}
}
  相关解决方案