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