Home | 简体中文 | 繁体中文 | 杂文 | Github | 知乎专栏 | Facebook | Linkedin | Youtube | 打赏(Donations) | About
知乎专栏

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