下面來繼續記錄並分享ES相關:
下面來分享一個連接ES集羣的方法,如下所示:
/**
* create by wxy_jdhk
*/
public class ElasticSearchUtils {
//json格式 數據綁定demo1
public String createJsonDemoOne() {
String json = "{" +
"\"user\":\"kimchy\"," +
"\"postDate\":\"2013-01-30\"," +
"\"message\":\"trying out Elasticsearch\"" +
"}";
return json;
}
//json格式 數據綁定demo2
public Map<String, Object> createJsonDemoTwo() {
Map<String, Object> json = new HashMap<String, Object>();
json.put("user", "kimchy");
json.put("postDate", new Date());
json.put("message", "trying out Elasticsearch");
return json;
}
//json格式 數據綁定demo3
//綁定集羣
public void connectionCluster() {
//bind cluster
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearch").build();
TransportClient client = new PreBuiltTransportClient(settings);
//Jackson Databind
//instance a json mapper
ObjectMapper mapper = new ObjectMapper(json, json, false, null, null, null, null, settings);
client.close();
}