0
我在SQL Server管理工作室有一些記錄,我想索引他們到我的ES索引。 目前我正在索引他們單獨的這是需要很長時間。我想批量索引它們。我嘗試使用批量描述符它是拋出一個錯誤說>對象索引,如果沒有手動設置ID將從對象推斷它將推斷從對象從數據庫檢索數據和批量索引他們 - SQL Server
下面是我的代碼。
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);
客戶端設置
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);
有沒有什麼辦法比的描述符索引數千個文件的有效方式等?
在此先感謝
查看一些設置int https://www.elastic.co/blog/performance-considerations-elasticsearch-indexing和https://www.elastic.co/blog/performance-indexing- 2-0。科學測量,找到適合您的文檔,硬件和環境的批量請求大小的最佳位置 –
感謝Russ Cam。但在檢查替代方法之前,我的代碼是否正確?因爲當我使用我的代碼時,它在Descriptor部件附近拋出一個錯誤。 TIA – ASN
您應該批量發送批量請求文件。在每個批量請求中發送的文檔數量取決於文檔結構,硬件和環境,因此您需要通過實驗爲您的場景找到最佳批量大小。我傾向於從數據庫分頁記錄併發送每頁批量請求 –