Hi,
I am using IndexRequest to send data to an elasticsearch index.
I had recently set up XPACK on my ES cluster. So now sending data to the index causes an authentication error. Could anyone please guide me as to how to send data to a password protected index using IndexRequest. Below is the code I am using.
IndexRequest request = new IndexRequest(
"test_data",
"doc");
for(int x=0;x<test_Data.size();x++) {
HashMap<String,String> tempHashMap = test_Data.get(x);
XContentBuilder builder = jsonBuilder()
.startObject()
.field("client_code",tempHashMap.get("client_code"))
.endObject();
String json = builder.string();
request.source(json, XContentType.JSON);
IndexResponse indexResponse = client.index(request);}
I am getting error -
Suppressed: org.elasticsearch.client.ResponseException: method [POST], host [http://localhost:9200], URI [/test_data/doc?timeout=1m], status line [HTTP/1.1 401 Unauthorized]
{"error":{"root_cause":[{"type":"security_exception","reason":"missing authentication token for REST request [/test_data/doc?timeout=1m]","header":{"WWW-Authenticate":"Basic realm="security" charset="UTF-8""}}],"type":"security_exception","reason":"missing authentication token for REST request [/test_data/doc?timeout=1m]","header":{"WWW-Authenticate":"Basic realm="security" charset="UTF-8""}},"status":401}