NEST 索引DataSet数据,先序列化然后转成dynamic 类型进行索引;
public void Insert(DataSet dataSet,int taskId) { StructureData(dataSet); foreach (DataTable table in dataSet.Tables) { string indexName = string.Format("mailtask{0}",taskId); string typeName = string.Format("{0}info",table.TableName); // string js= JsonConvert.SerializeObject(table); dynamic dc = JsonConvert.DeserializeObject<dynamic>(js); IndexManyExtensions.IndexManyAsync(SimpleClient.Client, dc, indexName, typeName); //SimpleClient.Client.IndexMany(dc, indexName, typeName); } } private void StructureData(DataSet dataSet) { DateTime sendTime = DateTime.Now; foreach (DataTable table in dataSet.Tables) { table.Columns.Add(new DataColumn("SendTime",typeof(DateTime)) {DefaultValue = sendTime}); } }
时间: 2024-11-09 02:54:31