oracle - Taking too long to insert records in Elasticsearch in c# -


the following code pulls data 2 tables table1 , table2, performs join on them, on field 3 , indexes elasticsearch. total number or rows need indexing around 500 million. code inserts 5 million records in 1 hour, way take 100 hours complete. there way can make faster?

        public static void selection()         {             uri node = new uri("http://localhost:9200");             connectionsettings settings = new connectionsettings(node);             elasticclient client = new elasticclient(settings);              int batchsize = 100;             string query = "select table1.field1, table2.field2 table1 join table2 on table1.field3=table2.field3";              try             {                 oraclecommand command = new oraclecommand(query, con);                 oracledatareader reader = command.executereader();                  list<record> l = new list<record>(batchsize);                 string[] str = new string[2];                 int currentrow = 0;                  while (reader.read())                 {                     (int = 0; < 2; i++)                         str[i] = reader[i].tostring();                     l.add(new record(str[0], str[1]));                      if (++currentrow == batchsize)                     {                         commit(l, client);                         l.clear();                         currentrow = 0;                     }                 }                 commit(l, client);             }             catch(exception er)             {                 console.writeline(er.message);             }          }          public static void commit(list<record> l, elasticclient client)         {             bulkdescriptor = new bulkdescriptor();             foreach (var x in l)                 a.index<record>(op => op.object(x).index("index").type("type"));             var res = client.bulk(d => a);             console.writeline("100 records more inserted.");         } 

any appreciated! :)

can try using lower level client i.e. elasticsearchclient ?

here sample example -

//fill data in elasticdatarows  stringbuilder elasticdatarows = new stringbuilder() elasticdatarows.appendline("{ \"index\":  { \"_index\": \"testindex\", \"_type\": \"accounts\" }}"); elasticdatarows.appendline(jsonconvert.serializexmlnode(objxml, newtonsoft.json.formatting.none, true));  var node = new uri(objextsetting.selectsinglenode("settings/elasticsearchurl").innertext); var config = new connectionconfiguration(node); elasticsearchclient objelasticclient = new elasticsearchclient(config);  //insert data elasticsearch var response = extractioncontext.objelasticclient.bulk(message.elasticdatarows.tostring()); 

elasticsearchclient not typed nest. can convert class object data json using newtonsoft.json.

as per testing more faster nest api.

thanks, sameer


Comments

Popular posts from this blog

python - No exponential form of the z-axis in matplotlib-3D-plots -

php - Best Light server (Linux + Web server + Database) for Raspberry Pi -

c# - "Newtonsoft.Json.JsonSerializationException unable to find constructor to use for types" error when deserializing class -