Adding a Document in Java


I would like to add a document to a collection in ElasticSearch using Java. Is there a sample program with explanation available?

Thank You


I hope this is right:

//Add documents

	Map<String, Object> jsonMap = new HashMap<>();
	jsonMap.put("user", "kimchy");
	jsonMap.put("postDate", new Date());
	jsonMap.put("message", "trying out Elasticsearch");
	IndexRequest indexRequest = new IndexRequest("posts", "doc", "1")
	IndexResponse indexResponse = (IndexResponse) client.index(indexRequest);

Also what about the 'Rest Client' code? Would it be the same?

Thank You

Thé link I pasted is for the rest Client.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.