I am reading excel sheet using java and aspose and I am using bulk API to push data to elasticsearch but it is taking more time to create index in elasticsearch and pushing data to ES. My Excel file contains 50000 records.
Please provide solution.
Below is my code.
Settings settings = Settings.builder()
.put("cluster.name", "elasticsearchtest").build();
TransportClient client = new PreBuiltTransportClient(settings)
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("172.21.153.176"),9300));
BulkRequestBuilder brb = client.prepareBulk();
FileInputStream file = new FileInputStream(new File("C:\Users\cajitb\Desktop\TempFiles\op\TestExcel.xlsx"));
Workbook workbook = new Workbook(file);
Worksheet worksheet = workbook.getWorksheets().get(0);
Cells cells = worksheet.getCells();
Range range = cells.getMaxDisplayRange();
int totalColumns = range.getColumnCount();
int totalRows = range.getRowCount();
RowCollection rows = cells.getRows();
int maxColumn = cells.getMaxDataColumn();
int maxRows = cells.getMaxDataRow();
System.out.println("Max Col="+maxColumn);
System.out.println("Max Row="+maxRows);
System.out.println("Total Cols="+totalColumns);
System.out.println("Total Rows="+totalRows);
Date d1 = new Date();
System.out.println("Start Time:"+dateFormat.format(d1));
List<Object> colList = new ArrayList<Object>();
for(int i = 0; i<=0 ; i++)
{
for (int j = 0; j < totalColumns; j++)
{
colList.add(cells.get(i, j).getValue());
}
}
System.out.println("Col List ="+colList);
for (int i = 1; i < rows.getCount(); i++)
{
for (int j = 0; j < totalColumns; j++)
{
String key = (String)colList.get(j);
if(null==key)
key = "";
hm.put(key, cells.get(i, j).getValue());
System.out.print(cells.get(i, j).getValue() + "\t");
}
hm.put("Action_Date", dateFormat.format(new Date()));
brb.add(client.prepareIndex("xxxxindex", "xxxxtype").setSource(hm));
System.out.println("");
}
Date d2 = new Date();
System.out.println("End Time:"+dateFormat.format(d2));
System.out.println("Col List ="+colList);
BulkResponse response = brb.execute().actionGet();
if(response.hasFailures()) {
System.err.println(response.buildFailureMessage());
} else {
System.out.println("Bulk indexing succeeded."+response.status());
}