ElasticSearch.Net - 更新包含多个组件的数组

ElasticSearch.Net - Update array with multiple components

我已使用 ElasticSearch 为数据建立索引,但我在更新特定字段时遇到问题。 JSON的一个片段如下:

 {
 "_index": "indexName",
 "_type": "type",
 "_id": "00001",
 "colors": [
     "red",
     "green"
 ]
 "place": "london",
 "person": [
      {
           "name": "john",
           "age": "27",
           "eyes": "blue"
      }
      {
           "name": "mary",
           "age": "19",
           "eyes": "green"
      }

 ]
 }

我需要添加一个新的 person 对象,例如:

{
    "name": "jane",
    "age": "30",
    "eyes": "grey"
}

我已经 People 定义如下:

public class People
{
    public List<string> colors {get; set; }
    public string place {get; set; }
    public List<Person> person {get; set; }
}
public class Person
{
    public string name {get; set; }
    public string age {get; set; }
    public string eyes {get; set; }
}

我更新 color 没有任何问题:

client.Update<People>(u => u
    .Id(u.Id)
    .Index(u.Index)
    .Type(u.Type)
    .Script("if ctx._source.containsKey(\"color\")) { ctx._source.color += color; } else { ctx._source.color = [color] }")
    .Params(p => p
        .Add("color", "pink"))
);

虽然我不知道如何更新 person 字段,因为它是 Person 对象的列表而不是字符串列表。

非常感谢任何帮助!

我之前通过使用匿名对象并将部分文档更新发送到 Elasticsearch 以仅更新需要的部分来完成此操作。

这是一个应该有效的代码片段...

var peopleId = //Get Id of document to be updated.
var persons = new List<Person>(3);
persons.Add(new Person { name = "john", eyes = "blue", age = "27" });
persons.Add(new Person { name = "mary", eyes = "green", age = "19" });
persons.Add(new Person { name = "jane", eyes = "grey", age = "30" });

var response = Client.Update<People, object>(u => u
            .Id(peopleId)
            .Doc(new { person = persons})
            .Refresh()
        );