Home | 簡體中文 | 繁體中文 | 雜文 | 知乎專欄 | Github | OSChina 博客 | 雲社區 | 雲棲社區 | Facebook | Linkedin | 視頻教程 | 打賞(Donations) | About
知乎專欄多維度架構 | 微信號 netkiller-ebook | QQ群:128659835 請註明“讀者”

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