Hi all,
I have some records in SQL Server management studio and I want to index them to my ES index.
At present I'm indexing them individually which is taking a long time. I would like to bulk index them. I tried using the Bulk Descriptor it is throwing an error saying > the object to index, if id not set manually it will be inferred from the object
below is my code.
string connectionString = ConfigurationManager.ConnectionStrings["MyDbConn"].ToString();
using (cn = new SqlConnection(connectionString))
{
cmd = new SqlCommand();
cmd.CommandText = ConfigurationManager.AppSettings["dbName"];
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = cn;
cn.Open();
//to index the students response into the ES
try
{
client = ConfigSettings.connection();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
throw;
}
reader = cmd.ExecuteReader();
while (reader.Read())
{
var descriptor = new BulkDescriptor();
descriptor.Index<Class1>(b=>b.Document(new Class1
{
Id = Int32.Parse(reader[0].ToString()),
Title = reader[1].ToString(),
BodyContent = reader[2].ToString()
}, z => z.Refresh()));
}
Client.Bulk(descriptor);
Client settings
configvalue1 = ConfigurationManager.AppSettings["url"];
var pool = new SingleNodeConnectionPool(new Uri(configvalue1));
var defaultIndex = "dbtrial";
settings = new ConnectionSettings(pool)
.DefaultIndex(defaultIndex)
.MapDefaultTypeNames(m => m.Add(typeof(Class1), "records"))
client = new ElasticClient(settings);
client.createIndex(defaultIndex);
Is there any way other than descriptor to index thousands of documents in a efficient way?
Thanks In Advance