0

我一直在尝试使用批量插入功能,但每次使用它都会显示一些映射错误。批量插入函数声明是否已从嵌套 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; }

}

4

1 回答 1

2

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

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

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

于 2017-04-20T14:22:29.260 回答