gpt4 book ai didi

c# - 使用NEST C#在Elastic搜索中删除嵌套文档

转载 作者:行者123 更新时间:2023-12-03 02:03:06 25 4
gpt4 key购买 nike

如何使用Nest库在 Elasticsearch 中仅删除嵌套对象而不删除索引。

public class Make
{
public string MakeId {get;set;}
public string MakeName {get;set;}
public string Address { get;set;}

[ElasticProperty(Type = FieldType.Nested)]
public List<Cars> Models {get;set;}
}

在上面的映射中,我想删除一个Models条目而不删除整个索引。

我尝试使用DeleteByQuery删除,但它会删除整个Make索引。

最佳答案

如果您不介意脚本,可以尝试:

var updateResponse = client.Update<Make>(descriptor => descriptor
.Id(documentId)
.Script("ctx._source.models.remove(0)")
.Lang("groovy"));

或不带脚本
var make = new Make {Id = "1", Models = new List<Cars>
{
new Cars{Name = "test"},
new Cars{Name = "test2"}
}};

make.Models.RemoveAt(1);

var updateResponse = client.Update<Make>(descriptor => descriptor
.Id("1")
.Doc(make));

关于c# - 使用NEST C#在Elastic搜索中删除嵌套文档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30032596/

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