当前位置: 代码迷 >> 综合 >> 3.2 JavaApi---索引
  详细解决方案

3.2 JavaApi---索引

热度:3   发布时间:2023-12-14 21:45:09.0

索引

创建

package pers.bik.es.index;import org.apache.http.HttpHost;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.client.indices.CreateIndexRequest;
import org.elasticsearch.client.indices.CreateIndexResponse;
import pers.bik.es.common.EsMessage;import java.io.IOException;/*** 创建索引* @author yangkaifei* @date 2021/8/22 6:46 下午* @cersion 1.0*/
public class Create {
    public static void main(String[] args) throws IOException {
    // 创建客户端RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost(EsMessage.ADDRESS,EsMessage.PORT,EsMessage.SCHEME)));CreateIndexRequest indexRequest = new CreateIndexRequest("chat");CreateIndexResponse createIndexResponse = client.indices().create(indexRequest, RequestOptions.DEFAULT);// 响应状态boolean acknowledged = createIndexResponse.isAcknowledged();System.out.println(String.format("响应状态 %s", acknowledged));// 关闭客户端client.close();}
}

github地址

创建索引

文章正在进行中。。。