gpt4 book ai didi

elasticsearch - 用于Elasticsearch Nest 5.x的批量插入

转载 作者:行者123 更新时间:2023-12-03 00:56:23 24 4
gpt4 key购买 nike

我一直在尝试使用批量插入功能,但是每次使用它都会显示一些映射错误。批量插入函数的声明是否已从nest 1.x更改为nest 5.x,因为在5.x nest文档中我没有找到.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; }

}

最佳答案

NEST似乎无法推断出您实体的正确类型,因为您指定了通用类型BaseData,而实际类型是TicketData。您应指定要建立索引的实体的实际类型。由于列表中可能有其他类型,因此可以使用GetType()方法获取实际类型:

descriptor.Index<BaseData>(op => op
.Document(recordList[j])
.Index(listOfIndexName[j])
.Type(recordList[j].GetType())
);

当前,您的查询尝试使用默认映射动态创建其他类型,而不是使用显式映射将其解释为现有类型

关于elasticsearch - 用于Elasticsearch Nest 5.x的批量插入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43511518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com