索引
创建
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;
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地址
创建索引
文章正在进行中。。。
|