NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{XY6cYmf7Sn-DRZgzeq3PBA}{localhost}{127.0.0.1:9300}]]

huangapple go评论103阅读模式
英文:

NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{XY6cYmf7Sn-DRZgzeq3PBA}{localhost}{127.0.0.1:9300}]]

问题

以下是翻译好的内容:

@Service
public class BulkApiService {
    private final Logger log = LoggerFactory.getLogger(BulkApiService.class);
    private String FOLDER_PATH = "src/main/resources/allRecipesJson";
    private String index = "test";

    @Autowired
    ElasticSearchConfig elasticSearchConfig;

    public String loadBulkData() throws UnknownHostException {
        Client client = elasticSearchConfig.client();
        AtomicReference<BulkRequestBuilder> request = new AtomicReference<>(client.prepareBulk());
        AtomicInteger counter = new AtomicInteger();
        try (Stream<Path> filePathStream = Files.walk(Paths.get(FOLDER_PATH))) {
            filePathStream.forEach(filePath -> {
                if (Files.isRegularFile(filePath)) {
                    counter.getAndIncrement();
                    try {
                        String content = Files.readString(filePath);
                        JSONObject jsonObject1 = new JSONObject(content);
                        HashMap yourHashMap1 = new Gson().fromJson(jsonObject1.toString(), HashMap.class);
                        request.get().add(client.prepareIndex(index, "default").setSource(yourHashMap1));

                    } catch (IOException ignore) {
                        log.error(ignore.toString());

                    }

                }
            });
            BulkResponse bulkResponse = request.get().execute().actionGet();

        } catch (Exception e) {
            log.error(e.toString());
        }

        return "已将批量数据加载到索引 " + index;
    }
}
@Configuration
public class ElasticSearchConfig {
    private static final Logger log = LoggerFactory.getLogger(ElasticSearchConfig.class);

    @Bean
    public Client client() {
        TransportClient client = null;
        try {
            client = new PreBuiltTransportClient(Settings.EMPTY)
                    .addTransportAddress(new TransportAddress(InetAddress.getByName("localhost"), 9300));

        } catch (UnknownHostException e) {
            log.error(log.toString());
        }
        return client;
    }
}

现在我想切换到 Elasticsearch 和 Kibana 版本 7.3.1。
我无法将数据加载到 Elasticsearch 索引中。在 IDE 日志中显示以下错误:

service.BulkApiService - NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{XY6cYmf7Sn-DRZgzeq3PBA}{localhost}{127.0.0.1:9300}]]

Elasticsearch 图像上的错误:

请帮助我进行纠正。

英文:

I am using BULK API of elasticsearch with version 5.6.16 of Elasticsearch and KIbana both.
The following code is working fine and uploading the code to an index of ES.

these are dependencies that I currently have.
> implementation 'org.springframework.boot:spring-boot-starter-data-elasticsearch'
>
> compile group: 'org.elasticsearch.client', name: 'transport'
>
> compile group: 'org.elasticsearch.plugin', name: 'transport-netty4-client'


@Service
public class BulkApiService {
private final Logger log = LoggerFactory.getLogger(BulkApiService.class);
private String FOLDER_PATH = &quot;src/main/resources/allRecipesJson&quot;;
private String index = &quot;test&quot;;
@Autowired
ElasticSearchConfig elasticSearchConfig;
public String loadBulkData() throws UnknownHostException {
Client client = elasticSearchConfig.client();
AtomicReference&lt;BulkRequestBuilder&gt; request = new AtomicReference&lt;&gt;(client.prepareBulk());
AtomicInteger counter = new AtomicInteger();
try (Stream&lt;Path&gt; filePathStream = Files.walk(Paths.get(FOLDER_PATH))) {
filePathStream.forEach(filePath -&gt; {
if (Files.isRegularFile(filePath)) {
counter.getAndIncrement();
try {
String content = Files.readString(filePath);
JSONObject jsonObject1 = new JSONObject(content);
HashMap yourHashMap1 = new Gson().fromJson(jsonObject1.toString(), HashMap.class);
request.get().add(client.prepareIndex(index, &quot;default&quot;).setSource(yourHashMap1));
} catch (IOException ignore) {
log.error(ignore.toString());
}
}
});
BulkResponse bulkResponse = request.get().execute().actionGet();
} catch (Exception e) {
log.error(e.toString());
}
return &quot;Bulk data loaded to index &quot; + index + &quot;&quot;;
}

Following is the configuration


@Configuration
public class ElasticSearchConfig {
private static final Logger log = LoggerFactory.getLogger(ElasticSearchConfig.class);
@Bean
public Client client() {
TransportClient client = null;
try {
client = new PreBuiltTransportClient(Settings.EMPTY)
.addTransportAddress(new TransportAddress(InetAddress.getByName(&quot;localhost&quot;), 9300));
} catch (UnknownHostException e) {
log.error(log.toString());
}
return client;
}
}

Now I want to move to Elasticserch and Kibana version 7.3.1.
I am unable to load the data to the elasticsearch index. The following error is shown on IDE Log
>service.BulkApiService - NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{XY6cYmf7Sn-DRZgzeq3PBA}{localhost}{127.0.0.1:9300}]]

The error on elasticsearch imagec

Kindly help me to correct it.

答案1

得分: 0

@Service
public class BulkApiService {
private final Logger log = LoggerFactory.getLogger(BulkApiService.class);
private String FOLDER_PATH = "src/main/resources/allRecipesJson";
private String index = "test1";
private static final String TYPE = "test_type";
@Autowired
private RestHighLevelClient restHighLevelClient;
public String loadBulkData() throws IOException {
BulkRequest bulkRequest = new BulkRequest();
AtomicInteger counter = new AtomicInteger();
try (Stream<Path> filePathStream = Files.walk(Paths.get(FOLDER_PATH))) {
filePathStream.forEach(filePath -> {
if (Files.isRegularFile(filePath)) {
counter.getAndIncrement();
System.out.println(filePath.toFile().getAbsoluteFile().toString());
try {
String content = Files.readString(filePath);
JSONObject jsonObject1 = new JSONObject(content);
HashMap yourHashMap1 = new Gson().fromJson(jsonObject1.toString(), HashMap.class);
IndexRequest indexRequest = new IndexRequest(index, TYPE).source(yourHashMap1);
bulkRequest.add(indexRequest);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
try {
restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
return "Bulk data loaded to index " + index;
}
}

添加以下依赖项,并删除已放置的依赖项。

compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.4.2'
英文:

Following is the correct code.

@Service
public class BulkApiService { private final Logger log = LoggerFactory.getLogger(BulkApiService.class);
private String FOLDER_PATH = &quot;src/main/resources/allRecipesJson&quot;;
private String index = &quot;test1&quot;;
private static final String TYPE = &quot;test_type&quot;;
@Autowired
private RestHighLevelClient restHighLevelClient;
public String loadBulkData() throws IOException {
BulkRequest bulkRequest = new BulkRequest();
AtomicInteger counter = new AtomicInteger();
try (Stream&lt;Path&gt; filePathStream = Files.walk(Paths.get(FOLDER_PATH))) {
filePathStream.forEach(filePath -&gt; {
if (Files.isRegularFile(filePath)) {
counter.getAndIncrement();
System.out.println(filePath.toFile().getAbsoluteFile().toString());
try {
String content = Files.readString(filePath);
JSONObject jsonObject1 = new JSONObject(content);
HashMap yourHashMap1 = new Gson().fromJson(jsonObject1.toString(), HashMap.class);
IndexRequest indexRequest = new IndexRequest(index, TYPE).source(yourHashMap1);
bulkRequest.add(indexRequest);
} catch (IOException e) {
e.printStackTrace();
}
}
});
}
try {
restHighLevelClient.bulk(bulkRequest, RequestOptions.DEFAULT);
} catch (IOException e) {
e.printStackTrace();
}
return &quot;Bulk data loaded to index &quot; + index + &quot;&quot;;
}
}

Add the following dependency and remove the already placed dependencies.

> compile 'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.4.2'

huangapple
  • 本文由 发表于 2020年4月7日 23:13:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/61083353.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定