✨ Feat: [后台]:新增es依赖
This commit is contained in:
parent
f55c36e60d
commit
e44bbe7ddf
@ -95,6 +95,13 @@
|
||||
<version>1.2.56</version>
|
||||
</dependency>
|
||||
|
||||
<!--es操作依赖-->
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch.client</groupId>
|
||||
<artifactId>elasticsearch-rest-high-level-client</artifactId>
|
||||
<version>7.2.0</version>
|
||||
</dependency>
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
package com.fanxb.bookmark.common.util;
|
||||
|
||||
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 org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.common.xcontent.XContentBuilder;
|
||||
import org.elasticsearch.common.xcontent.XContentFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* 类功能简述:
|
||||
* 类功能详述:
|
||||
*
|
||||
* @author fanxb
|
||||
* @date 2019/7/19 16:07
|
||||
*/
|
||||
@Component
|
||||
public class EsUtil {
|
||||
|
||||
|
||||
public EsUtil() throws Exception {
|
||||
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("10.82.17.91", 9200, "http")));
|
||||
CreateIndexRequest request = new CreateIndexRequest("test-index");
|
||||
request.settings(Settings.builder().put("index.number_of_shards", 3).put("index.number_of_replicas", 2));
|
||||
XContentBuilder builder = XContentFactory.jsonBuilder();
|
||||
builder.startObject();
|
||||
{
|
||||
builder.startObject("properties");
|
||||
{
|
||||
builder.startObject("column1");
|
||||
{
|
||||
builder.field("type", "");
|
||||
builder.field("index", "not_analyzed");
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
}
|
||||
builder.endObject();
|
||||
request.mapping(builder);
|
||||
CreateIndexResponse res = client.indices().create(request, RequestOptions.DEFAULT);
|
||||
System.out.println(res);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
EsUtil util = new EsUtil();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user