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 = "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 + "";
}
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("localhost"), 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.