Adding a Document in Java

Hello

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

Thank You

This: https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-document-index.html

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")
	        .source(jsonMap);
	
	IndexResponse indexResponse = (IndexResponse) client.index(indexRequest);
	System.out.println(indexResponse.toString());

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.