天天看點

elasticsearch(三)調用TransportClient更新資料

調用client更新資料,使用UpdateRequest對象處理操作,具體的其他用法檢視api

private String index;
	private String type;

	@Autowired
	private TransportClient client;

	@Before
	public void prepare() {
		index = "database";
		type = "table";
	}



	/**
	 * 更新資料
	 */
	@Test
	public void updateTest() {
		// 此處ID是es裡面自己生成的ID,與資料ID無關
		String id = "AWb23S95Hj0kMOI7Sqr8";
		UpdateRequest updateRequest = new UpdateRequest(index, type, id);
		Map<String, String> map = new HashMap<>();
		map.put("name", "026");
		updateRequest.doc(map);
		client.update(updateRequest);
	}