# Java api index request

**URL:** <https://discuss.elastic.co/t/java-api-index-request/143166>\
**Category:** Elasticsearch\
**Created:** [August 6, 2018, 12:21pm UTC](https://discuss.elastic.co/t/java-api-index-request/143166 "2018-08-06T12:21:27Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ritwikkaul](https://avatars.discourse-cdn.com/v4/letter/r/839c29/32.png) [@ritwikkaul](https://discuss.elastic.co/u/ritwikkaul)\
**Post date:** [August 6, 2018, 12:21pm UTC](https://discuss.elastic.co/t/java-api-index-request/143166/1 "2018-08-06T12:21:27Z")

</div>

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](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}

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [August 6, 2018, 12:41pm UTC](https://discuss.elastic.co/t/java-api-index-request/143166/2 "2018-08-06T12:41:04Z")

</div>

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](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_basic_authentication.html)

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [September 3, 2018, 12:41pm UTC](https://discuss.elastic.co/t/java-api-index-request/143166/3 "2018-09-03T12:41:10Z")

</div>

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