package es_02_index; import org.elasticsearch.action.ActionListener; import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; import org.elasticsearch.action.support.master.AcknowledgedResponse; import org.elasticsearch.client.RestHighLevelClient; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; import java.io.IOException; /** * 删除索引异步操作 * * @author : qinyingjie * @version : 2.2.0 * @date : 2023/5/13 11:13 */ @SpringBootTest @RunWith(SpringRunner.class) public class TestIndex_06_delete { @Autowired private RestHighLevelClient client; @Test public void testDeleteIndexAsync() throws IOException { //创建删除索引请求 DeleteIndexRequest deleteIndexRequest = new DeleteIndexRequest("itheima_book"); // 执行 ActionListener listener = new ActionListener() { @Override public void onResponse(AcknowledgedResponse acknowledgedResponse) { //得到相应 boolean acknowledged = acknowledgedResponse.isAcknowledged(); System.out.println("acknowledged:" + acknowledged); } @Override public void onFailure(Exception e) { e.printStackTrace(); } }; } }