# Getting error while indexing the data to elasticsearch through JAVA API (when search guard is enabled ,)

**URL:** <https://discuss.elastic.co/t/getting-error-while-indexing-the-data-to-elasticsearch-through-java-api-when-search-guard-is-enabled/37693>\
**Category:** Elasticsearch\
**Created:** [December 21, 2015, 12:51pm UTC](https://discuss.elastic.co/t/getting-error-while-indexing-the-data-to-elasticsearch-through-java-api-when-search-guard-is-enabled/37693 "2015-12-21T12:51:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![balubollam](https://avatars.discourse-cdn.com/v4/letter/b/a587f6/32.png) [@balubollam](https://discuss.elastic.co/u/balubollam)\
**Post date:** [December 21, 2015, 12:51pm UTC](https://discuss.elastic.co/t/getting-error-while-indexing-the-data-to-elasticsearch-through-java-api-when-search-guard-is-enabled/37693/1 "2015-12-21T12:51:41Z")

</div>

```
      Hi Everyone

```

Please help me how to index data to es through java API when the searchguard is enabled

\*I have enabled ‘default authentication’ in elasticsearch.yml

Here is my elasticsearch.yml

###Default Authentication

#searchguard.authentication.http\_authenticator.impl:#com.floragunn.searchguard.authentication.http.HTTPUnauthenticatedAuthenticator

#searchguard.authentication.authentication\_backend.impl:#com.floragunn.searchguard.authentication.backend.simple.AlwaysSucceedAuthenticationBackend

\*Getting this following error when i connect through the java API:

Failed execution at org.elasticsearch.action.support.AdapterActionFuture.rethrowExecutionException(AdapterActionFuture.java:88)

```
at org.elasticsearch.action.support.AdapterActionFuture.actionGet(AdapterActionFuture.java:49)

```

Unauthenticated request (SEARCHGUARD\_UNAUTH\_REQ) for action indices:data/write/index

```
at com.floragunn.searchguard.filter.AbstractActionFilter.apply(AbstractActionFilter.java:158)

at org.elasticsearch.action.support.TransportAction$RequestFilterChain.proceed(TransportAction.java:165)

at org.elasticsearch.action.support.TransportAction.execute(TransportAction.java:82)

```

\*Here is my java program

package com.es.index;

import java.io.IOException;

import java.util.\*;

import org.elasticsearch.action.index.IndexResponse;

import org.elasticsearch.client.Client;

import org.elasticsearch.client.transport.TransportClient;

import org.elasticsearch.common.settings.ImmutableSettings;

import org.elasticsearch.common.settings.Settings;

import org.elasticsearch.common.transport.InetSocketTransportAddress;

import org.elasticsearch.common.xcontent.XContentBuilder;

import org.elasticsearch.common.xcontent.XContentFactory;

public class CreateIndex {

```
static TransportClient transportClient;

static IndexResponse response;

public static Client connectClient() {

    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name", "name").build();

    transportClient = new TransportClient(settings);

    transportClient = transportClient.addTransportAddress(new InetSocketTransportAddress("ip addess",9300));

    return transportClient;

}

```

public static String builtJson() throws IOException {  
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("user", "KT250")  
.field("Text", "Learning ES").endObject();  
String json = builder.string();  
System.out.print("data"+json);  
return json;  
}

public void indexDoc() {  
try  
{  
String json = builtJson();  
System.out.print("iam here"+json);  
/\*boolean indexExists=transportClient.prepareExists("em7").execute().actionGet().exists();  
if(indexExists)  
{  
transportClient.admin().indices().prepareCreate("em7").execute().actionGet();

```
}
else
{
System.out.print("this works\""+'"' + json +'"'+ "\"");*/

```

response = connectClient().prepareIndex("checkingindex", "s1").setSource(json).execute().actionGet();  
System.out.print("id created successfully"+response.getId());

```
}
catch(Exception e)
{
    e.printStackTrace();
}

```

}

public static void main(String args[]) {  
CreateIndex c=new CreateIndex();  
try {  
c.indexDoc();  
} catch (Exception e) {  
// TODO Auto-generated catch block  
e.printStackTrace();  
}  
}

}

Here is my configuration index

"acl":[

```
{

    "Comment":"By default no filters are executed and no filters a by-passed.

```

In such a case an exception is thrown and access will be denied.",

```
    "filters_bypass":[“”],

    "filters_execute":[]

 },

```

Thanks and regards

Balaji

---

<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:** [July 5, 2017, 11:29pm UTC](https://discuss.elastic.co/t/getting-error-while-indexing-the-data-to-elasticsearch-through-java-api-when-search-guard-is-enabled/37693/2 "2017-07-05T23:29:33Z")

</div>


