[英]Simple Existing Document Update in Elasticsearch using NEST
Hey I trying to update existing document
of ElasticSearch
, I found a cURL
code from Elasticsearch site Note: Sam
type with 2
document is already exists I just want to update a existing field 嘿,我试图更新ElasticSearch
现有document
,我从Elasticsearch网站找到了一个cURL
代码注意:带有2
文档的Sam
类型已经存在,我只想更新一个现有字段
POST /EmployeeIndex/Sam/2/_update
{
"doc" : {
"Nested" : true,
"views": 0
}
}
Its working perfectly how I need but please help me to convert it to NEST
, as i working on .NET
, I managed to write a code
它完美地满足了我的需要,但是当我在.NET
工作时,请帮助我将其转换为NEST
,我设法编写了code
var responseUpdate = client.Update<clsEmployeeElasticSearch, object>(u => u
.Index("EmployeeIndex")
.Type("Sam")
.Id(2)
.Doc(new { Nested= true })
.RetryOnConflict(3)
.Refresh());
But it always creating a new field in my document
instead of updating existing one. 但是它总是在我的document
创建一个新字段,而不是更新现有字段。 Please see attached screenshot with a code 请查看附带代码的屏幕截图 Please help guys. 请帮助大家。
What you need is a PartialUpdate
. 您需要的是PartialUpdate
。 Applied on your example, the following code should do what you expect. 将以下代码应用于您的示例,即可达到您的期望。
var responseUpdate = client.Update<clsEmployeeElasticSearch, object>(u => u
.Index("EmployeeIndex")
.Type("Sam")
.Id(2)
.Doc(new {IsActive ="true", Views="0"})
.DocAsUpsert()
);
Is it possible that you are already there but be just facing a casing missmatch issue? 是否有可能您已经在那儿了,但是正面临着外壳不匹配的问题? see from Nest reference : 请参阅Nest参考 :
Property Name Inference In many places NEST allows you to pass property names and JSON paths as C# expressions, ie: 属性名称推断在许多地方,NEST允许您将属性名称和JSON路径作为C#表达式传递,即:
.Query(q=>q .Term(p=>p.Followers.First().FirstName, "martijn")) NEST by default will camelCase properties. .Query(q => q .Term(p => p.Followers.First()。FirstName,“ martijn”))默认情况下,NEST将使用camelCase属性。 So the FirstName property above will be translated to "followers.firstName". 因此,上面的FirstName属性将转换为“ followers.firstName”。
This can be configured by setting 可以通过设置来配置
settings.SetDefaultPropertyNameInferrer(p=>p); settings.SetDefaultPropertyNameInferrer(p值=> P); This will leave property names untouched. 这将使属性名称保持不变。
Properties marked with [ElasticAttibute(Name="")] or [JsonProperty(Name="")] will pass the configured name verbatim. 标有[ElasticAttibute(Name =“”)]或[JsonProperty(Name =“”))]的属性将逐字传递配置的名称。
... Note that you are creating a dynamic object for the update so, i belive attributes might not a be a solution if you keep it that way ...请注意,您正在为更新创建动态对象,因此,如果保持这种方式,我相信属性可能不是解决方案
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.