弹性搜索根据条件批量更新部分更新文档中的记录

问题描述 投票:0回答:0

我正在使用 Nest 使用下面的嵌套代码批量更新 Elatsic 搜索。

// Insert
 var newdata1 = new DefaultSearchDTO{ Name="name 1", Description= "Desc 1", LastModified =DateTime.Parse( "2/1/2023")};
 var newdata2 = new DefaultSearchDTO { Name = "name 1", Description = "Desc 2", LastModified = DateTime.Parse("1/1/2022") };
 var newdata3 = new DefaultSearchDTO { Name = "name 1", Description = "Desc 3", LastModified = DateTime.Parse("1/1/2021") };

var insertlist = new List<DefaultSearchDTO> { newdata1, newdata2, newdata3 };
        
var objIndexResponse = await _objNestElasticClient.IndexManyAsync(insertlist.Cast<object>(), "myindex");
        
    
// Update
var updatedata1 = new DefaultSearchDTO { Name = "name 1", Description = "Desc 1 updated", LastModified = DateTime.Parse("1/1/1900") };
var updatedata2 = new DefaultSearchDTO { Name = "name 1", Description = "Desc 2 updated", LastModified = DateTime.Parse("1/1/2023") };
var  updatedata3 = new DefaultSearchDTO { Name = "name 1", Description = "Desc 3 updated", LastModified = DateTime.Parse("1/1/2023") };
var  updatelist = new List<DefaultSearchDTO> { updatedata1, updatedata2, updatedata3 };
    
objIndexResponse = await _objNestElasticClient.IndexManyAsync(updatelist.Cast<object>(), "myindex");

如果指定的值为“1/1/1900”,我希望弹性搜索忽略更新 lastmodifed 字段,在这种情况下,对于名称为 1 的记录,描述将被更新,但 lastmodified 将相同(部分更新)

所以运行后我期望的是

{ 名字=“名字1” , 描述 = "描述 1 更新”, LastModified ="2/1/2023") }

{ 名字=“名字2” , 描述 = "描述 2 更新”, LastModified ="1/1/2023") }

{ 名字 = "名字 3" , 描述 = "描述 3 更新”, LastModified ="1/1/2023") }

elasticsearch nest
© www.soinside.com 2019 - 2024. All rights reserved.