Elasticsearch Java REST高级客户端 删除索引

Elasticsearch Java REST高级客户端 删除索引

版本:Elasticsearch 7.2.0

1、索引是否存在

2、删除索引

3、创建客户端

4、maven配置---pom

1、索引是否存在

	/**
	 * 索引是否存在
	 * @param indexName
	 * @return
	 */
	public static boolean exists(String indexName) {
		RestHighLevelClient client = getClient();
		GetIndexRequest request = new GetIndexRequest(indexName); 
		request.local(false); 
		request.humanReadable(true); 
		request.includeDefaults(false); 
		try {
			return client.indices().exists(request, RequestOptions.DEFAULT);
		} catch (IOException e) {
			
			e.printStackTrace();
			return false;
		}
	}

2、删除索引

	/**
	 * 删除索引
	 */
	public static void deleteIndex() {
		String indexName = "alert_pinghost-min-2019-11-20";
		boolean exists = exists(indexName);
		if(!exists) {
			//不存在就结束
			return ;
		}
		//索引存在,就执行删除
		long s = System.currentTimeMillis();
		RestHighLevelClient client = getClient();
		DeleteIndexRequest request = new DeleteIndexRequest(indexName); 
		request.timeout(TimeValue.timeValueMinutes(2)); 
		request.timeout("2m");
		try {
			AcknowledgedResponse delete = client.indices().delete(request, RequestOptions.DEFAULT);
			
		} catch (IOException e) {
			e.printStackTrace();
		}finally {
			try {
				client.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		long t = System.currentTimeMillis();
		//计算删除耗时
		System.out.println(t-s);
	}

3、创建客户端

REST高级客户端多种方式连接:https://blog.csdn.net/u014646662/article/details/98966833

4、maven配置---pom

Elasticsearch Java REST高级客户端 maven配置

https://blog.csdn.net/u014646662/article/details/97895028

5、对人工智能感兴趣点下面链接

现在人工智能非常火爆,很多朋友都想学,但是一般的教程都是为博硕生准备的,太难看懂了。最近发现了一个非常适合小白入门的教程,不仅通俗易懂而且还很风趣幽默。所以忍不住分享一下给大家。点这里可以跳转到教程。

https://www.cbedai.net/u014646662
 

发布了139 篇原创文章 · 获赞 273 · 访问量 666万+

猜你喜欢

转载自blog.csdn.net/u014646662/article/details/103197246