@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();} }