I've got data indexed using ElasticSearch, and I'm having trouble updating a particular field. A snippet of the JSON is as follows:
{
"_index": "indexName",
"_type": "type",
"_id": "00001",
"colors": [
"red",
"green"
]
"place": "london",
"person": [
{
"name": "john",
"age": "27",
"eyes": "blue"
}
{
"name": "mary",
"age": "19",
"eyes": "green"
}
]
}
I need to add in a new person
object, something like:
{
"name": "jane",
"age": "30",
"eyes": "grey"
}
I've got People
defined as follows:
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; }
}
I updated color
with no problems by doing:
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"))
);
I can't figure out how to update the person
field though, as it's a list of Person
objects rather than a list of strings.
Any help is greatly appreciated!