鉴于以下文档,我将如何以嵌套类型添加新文档。仅当文档不存在时,才应添加该文档。
{
"mappings": {
"properties": {
"isn" : { "type":"text" },
"title" : { "type":"text" },
"article": {
"type": "nested"
}
}
}
}
PUT journal/_doc/1
{
"isn" : "11223344",
"article" : [
{
"id" : 1,
"title" : "first article title",
"author" : "John"
},
{
"id" : 2,
"title" : "second article title",
"author" : "Carl"
}
]
}
此脚本将不断重复添加...仅当(id = 3)不存在时,如何添加。
"script": {
"source": "ctx._source.articles.add(params.article)",
"params": {
"article": {
"id": 3,
"title": "new article tile",
"author": "Leo"
}
}
}
}