大数据技术之Elasticsearch-Java API操作(一)API基本操作

删除索引

1)源代码

@Test

public void deleteIndex(){

// 1 删除索引

client.admin().indices().prepareDelete("blog2").get();

// 2 关闭连接

client.close();

}

2)查看结果

浏览器查看http://hadoop102:9200/blog2

没有blog2索引了。

{"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"blog2","index_uuid":"_na_","index":"blog2"}],"type":"index_not_found_exception","reason":"no such index","resource.type":"index_or_alias","resource.id":"blog2","index_uuid":"_na_","index":"blog2"},"status":404}

********自己操作********

Java代码:

@Test
    public void deleteIndex() {
        client.admin().indices().prepareDelete("blog").get();
        // 关掉连接
        client.close();
    }

结果:

 

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3