簡體   English   中英

NoNodeAvailableException[沒有配置的節點可用:[{#transport#-1}{XY6cYmf7Sn-DRZgzeq3PBA}{localhost}{127.0.0.1:9300}]]

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

我正在使用 elasticsearch 的 BULK API 和 Elasticsearch 和 KIbana 的 5.6.16 版本。 以下代碼工作正常並將代碼上傳到 ES 的索引。

這些是我目前擁有的依賴項。

實施 'org.springframework.boot:spring-boot-starter-data-elasticsearch'

編譯組:'org.elasticsearch.client',名稱:'transport'

編譯組:'org.elasticsearch.plugin',名稱:'transport-netty4-client'


@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 "Bulk data loaded to index " + 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;
    }
}

現在我想遷移到 Elasticserch 和 Kibana 版本 7.3.1。 我無法將數據加載到 elasticsearch 索引。 IDE 日志顯示以下錯誤

service.BulkApiService - NoNodeAvailableException[配置的節點都不可用:[{#transport#-1}{XY6cYmf7Sn-DRZgzeq3PBA}{localhost}{127.0.0.1:9300}]]

elasticsearch imagec 上的錯誤

請幫我糾正它。

以下是正確的代碼。

@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 + "";
    }
}

添加以下依賴項並刪除已放置的依賴項。

編譯'org.elasticsearch.client:elasticsearch-rest-high-level-client:6.4.2'

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM