# 添加一条数据
POST /blog-test/doc/AXiHn9l3CFuw25Pb9kYM
{
"title": "Invest Money",
"body": "Please start investing money as soon...",
"tags": [
"money",
"invest"
],
"published_on": "18 Oct 2017",
"comments": [
{
"name": "William",
"age": 34,
"rating": 8,
"comment": "Nice article..",
"commented_on": "30 Nov 2017"
},
{
"name": "John",
"age": 38,
"rating": 9,
"comment": "I started investing after reading this.",
"commented_on": "25 Nov 2017"
},
{
"name": "Smith",
"age": 33,
"rating": 7,
"comment": "Very good post",
"commented_on": "20 Nov 2017"
}
]
}
# 数组添加一条数据
POST /blog-test/doc/AXiHn9l3CFuw25Pb9kYM/_update
{
"script": {
"source": "ctx._source.comments.add(params.new_comment)",
"params": {
"new_comment": {
"name": "xiang",
"age": 25,
"rating": 18,
"comment": "very very good article...",
"commented_on": "3 Nov 2018"
}
}
}
}
# 数组移除一条数据
POST /blog-test/doc/AXiHn9l3CFuw25Pb9kYM/_update
{
"script": {
"lang": "painless",
"source": "ctx._source.comments.removeIf(it -> it.name == 'John');"
}
}
# 数组更新一条数据
POST /blog-test/doc/AXiHn9l3CFuw25Pb9kYM/_update
{
"script": {
"source": "for(e in ctx._source.comments){if (e.name == 'Smith') {e.age = 25; e.comment= 'very very good article...';}}"
}
}