不要急,总有办法的

Elasticsearch5.X添加searchguard后TransportClient如何连接

Elasticsearch | 作者 xinghaipili | 发布于2017年05月20日 | 阅读数:9063

Elasticsearch5.X添加searchguard后TransportClient如何连接
已邀请:

chendaoqiu - 90后IT

赞同来自:

同问

xtc001

赞同来自:

求如何解决 javaclient settings如何设置

jzbrt

赞同来自:

请问你们用的什么集群管理工具?

lulongzhou

赞同来自:

我也遇到了同样的问题。请问楼主这个问题解决了吗?能共享一下吗?谢谢!

lydouble0

赞同来自:

同问

lulongzhou

赞同来自:

楼主我刚刚解决了,分享一下,下面是我的代码:

public static void main(String[] args) throws UnknownHostException {
        Settings settings = Settings.builder()
                .put("path.home", ".")
                .put("path.conf", "E:\\workspace_idea\\es_test\\src\\main\\resources")
                .put("cluster.name", "es-cluster")
                .put("searchguard.ssl.transport.enabled", true)
                .put("searchguard.ssl.transport.keystore_filepath", "sgadmin-keystore.jks")
                .put("searchguard.ssl.transport.truststore_filepath", "truststore.jks")
                .put("searchguard.ssl.http.keystore_password", "password")
                .put("searchguard.ssl.http.truststore_password", "password")
                .put("searchguard.ssl.transport.keystore_password", "password")
                .put("searchguard.ssl.transport.truststore_password", "password")
                .put("searchguard.ssl.transport.enforce_hostname_verification", false)
                .build();

        TransportClient client = new PreBuiltTransportClient(settings, SearchGuardSSLPlugin.class)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("ip-1"), 9300))
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("ip-2"), 9300))
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("ip-3"), 9300));

        client.admin().cluster().nodesInfo(new NodesInfoRequest()).actionGet();

        //搜索数据
        GetResponse response = client.prepareGet("test", "name", "1").execute().actionGet();
        //输出结果
        System.out.println(response.getSourceAsString());
        //关闭client
        client.close();
    }

lydouble0

赞同来自:

厉害!  先试试

yanlei

赞同来自:

按照楼上的说法 我能创建client  但是报错没权限操作索引 有人知道什么原因吗?

Exception in thread "main" ElasticsearchSecurityException[no permissions for indices:data/read/search]

要回复问题请先登录注册