我一直在尝试使用批量插入功能,但每次使用它时都会显示一些映射错误。批量插入函数声明是否已从嵌套1.x更改为嵌套5.x,因为在5.x嵌套文档中我没有找到.bulk()函数。请建议
批量插入代码:
public void bulkInsert(List<BaseData> recordList, List<String> listOfIndexName)
{
BulkDescriptor descriptor = new BulkDescriptor();
descriptor.Index<BaseData>(op => op
.Document(recordList[j])
.Index(listOfIndexName[j])
);
}
var result = clientConnection.Bulk(descriptor);
}
我传递的数据列表如下所示:
[ElasticsearchType(IdProperty = "number")]
class TicketData : BaseData
{
//[ElasticProperty(Index = FieldIndexOption.NotAnalyzed, Store = true)]
[Date(Name = "sys_updated_on", Store = true)]
public DateTimeOffset sys_updated_on { get; set; }
[Text(Name = "number", Store = true)]
public override string number { get; set; }
[Text(Name = "incident_state", Store = true)]
public string incident_state { get; set; }
[Text(Name = "location", Store = true)]
public string location { get; set; }
[Text(Name = "assigned_to", Store = true)]
public string assigned_to { get; set; }
[Text(Name = "u_knowledge_id", Store = true)]
public string u_knowledge_id { get; set; }
[Text(Name = "u_knowledge_id.u_process_role", Store = true)]
public string u_knowledge_id_u_process_role { get; set; }
}
答案 0 :(得分:2)
似乎NEST无法推断出您的实体的正确类型,因为您指定了泛型BaseData
,而实际类型为TicketData
。您应该指定要编制索引的实际实体类型。由于列表中可能包含不同类型,因此您可以使用GetType()
方法获取实际类型:
descriptor.Index<BaseData>(op => op
.Document(recordList[j])
.Index(listOfIndexName[j])
.Type(recordList[j].GetType())
);
目前,您的查询尝试使用默认映射动态创建不同的类型,而不是将其解释为具有显式映射的现有类型