我在localhost:9200上运行Elasticsearch 2.1.0。我需要做的是使用Java for ES从索引中读取数据,而不必创建节点,因为我关心应用程序的速度。以下是我的代码:

try (Client client = TransportClient.builder().build()
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9200))
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9200))) {
            QueryBuilder qb = matchQuery(
                    ...
            );
            CountResponse response;
            response = client.prepareCount(indexName)
                    .setTypes(spammerType).setQuery(qb)
                    .execute()
                    .actionGet();
        }

但是,我收到以下错误:
Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{127.0.0.1}{localhost/127.0.0.1:9200}]]

但是我试图避免创建节点,因为如前所述,我需要我的应用程序尽可能快地从索引中读取。根据ES:



我该如何解决错误?谢谢。

最佳答案

显然,我应该在端口9300而不是9200上运行它:

.addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9300))
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getLocalHost(), 9300)))

10-07 13:57