import org.elasticsearch.action.index.IndexResponse; import org.elasticsearch.client.Client; IndexResponse response = client.prepareIndex("information", "news", "1") .setSource("{ \"title\": \"ElasticSearch 5.5.2\"}") .get();
使用 HashMap 插入
public void createData() { Map<String, Object> map = new HashMap<String, Object>(); map.put("name", "Neo Chen"); map.put("age", 30); map.put("book", new String[]{"Netkiller Linux 手札","Netkiller Java 手札"}); map.put("website", "http://www.netkiller.cn"); map.put("email", "netkiller@msn.com"); IndexResponse response = client.prepareIndex("book", "author", UUID.randomUUID().toString()) .setSource(map).get(); System.out.println("Status: " + response.status().getStatus() + "!id=" + response.getId()); }
原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。