In this tutorial I will show you how to perform a POST request. If you have not connected first please do so before continuing.
Imports
import org.apache.http.HttpEntity; import org.apache.http.nio.entity.NStringEntity; import org.apache.http.entity.ContentType; import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Response;
Now we can perform the POST to ElasticSearch.
final Integer id = 1; final String document = "{\"key\": 1 }"; final HttpEntity httpEntity = new NStringEntity(document, ContentType.APPLICATION_JSON); final Response response = restHighLevelClient.getLowLevelClient().performRequest("POST", "/indexName/indexType/" + id, Collections.<String, String>emptyMap(), httpEntity); //Now you can print the response System.out.println(EntityUtils.toString(response.getEntity()));
You must be logged in to post a comment.