I have the following code written in C #, but according to this, it will take me 4-5 days to transfer data from Oracle database to Elasticsearch. I insert records in batches of 100. Is there any other way in which the migration of 4 million records is faster (perhaps less than a day, if possible)?
public static void Selection() { for(int i = 1; i < 4000000; i += 1000) { for(int j = i; j < (i+1000); j += 100) { OracleCommand cmd = new OracleCommand(BuildQuery(j), oracle_connection); OracleDataReader reader = cmd.ExecuteReader(); List<Record> list=CreateRecordList(reader); insert(list); } } } private static List<Record> CreateRecordList(OracleDataReader reader) { List<Record> l = new List<Record>(); string[] str = new string[7]; try { while (reader.Read()) { for (int i = 0; i < 7; i++) { str[i] = reader[i].ToString(); } Record r = new Record(str[0], str[1], str[2], str[3], str[4], str[5], str[6]); l.Add(r); } } catch (Exception er) { string msg = er.Message; } return l; } private static string BuildQuery(int from) { int to = from + change - 1; StringBuilder builder = new StringBuilder(); builder.AppendLine(@"select * from"); builder.AppendLine("("); builder.AppendLine("select FIELD_1, FIELD_2, FIELD_3, FIELD_4, FIELD_5, FIELD_6, FIELD_7, "); builder.Append(" row_number() over(order by FIELD_1) rn"); builder.AppendLine(" from tablename"); builder.AppendLine(")"); builder.AppendLine(string.Format("where rn between {0} and {1}", from, to)); builder.AppendLine("order by rn"); return builder.ToString(); } public static void insert(List<Record> l) { try { foreach(Record r in l) client.Index<Record>(r, "index", "type"); } catch (Exception er) { string msg = er.Message; } }
source share