Java api index request

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}

Most likely you either activated a trial license (with security) or added a gold or platinum license.

You need either to go back to basic license (no security) or better to change the way you are building your client. See https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html

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