Elasticsearch Nest 5.x的散装插入物



我一直在尝试用于批量插入功能,但是每次使用它时,都会显示一些映射错误。有批量插入功能声明已从Nest 1.x变为Nest 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; }

}

似乎Nest无法推断实体的正确类型,因为您指定了通用类型BaseData,而实际类型为TicketData。您应该指定要索引的实体的实际类型。由于您的列表内可能具有不同的类型,因此可以使用GetType()方法获得实际类型:

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

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

最新更新