Home | 简体中文 | 繁体中文 | 杂文 | 打赏(Donations) | ITEYE 博客 | OSChina 博客 | Facebook | Linkedin | 知乎专栏 | Search | About

21.2. insert

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());
}