我有以下索引映射
{
"mappings": {
"xxxxx": {
"properties": {
"ID": {
"type": "text"
},
"pairs": {
"type": "nested"
},
"xxxxx": {
"type": "text"
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
该pairs
字段是具有以下结构的对象数组
{
"id": "",
"Answer": "",
"Question": []
}
Run Code Online (Sandbox Code Playgroud)
我想做的是检索特定的嵌套对象并更新它。我已经尝试过updateByQuery
使用部分文档/脚本的方法,但我无法更新
脚本
var theScript = {
"inline": "ctx._source.Answer = 'Elastic search update Test'"
}
client.updateByQuery({
index: 'sample',
_source: false,
body: {
query: {
bool: {
must: [
{
"match": {
"ID": '2rXdCf5OM9g1ebPNFdZNqW'
}
},
{
"nested": {
"path": "pairs",
"query": {
"match": {
"pairs.id": "c1vNGnnQLuk"
}
},
"inner_hits": {}
}
}
]
}
},
"script": theScript
}
},function(err, body){
if(err){
throw err;
}
console.log('body: ', body)
console.log('data: ', body.hits.hits)
})
Run Code Online (Sandbox Code Playgroud)
部分文档
client.updateByQuery({
index: 'sample',
_source: false,
body: {
query: {
bool: {
must: [
{
"match": {
"ID": '2rXdCf5OM9g1ebPNFdZNqW'
}
},
{
"nested": {
"path": "pairs",
"query": {
"match": {
"pairs.id": "c1vNGnnQLuk"
}
},
"inner_hits": {}
}
}
]
}
},
"doc": {
"Answer": 'Elastic search update Test'
}
}
},function(err, body){
if(err){
throw err;
}
console.log('body: ', body)
console.log('data: ', body.hits.hits)
})
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
部分更新
Error: [parsing_exception] Unknown key for a START_OBJECT in [doc]., with { line=1 & col=191 }
Run Code Online (Sandbox Code Playgroud)
脚本
Error: [illegal_argument_exception] [sample][conversation][AWa-p9zBTJHq-_gvo-Af] didn't store _source
Run Code Online (Sandbox Code Playgroud)
注意我理想地希望为此使用部分文档更新,因为嵌套对象有点复杂,并且不可能编写内联脚本
Elasticsearch 版本 - 5.6
更新
做这样的事情有效
{
"script" : {
"inline": "ctx._source.pairs= params.pairs",
"lang": "painless",
"params" : {
"pairs" : [{...}, {...}, ...]
}
}
}
Run Code Online (Sandbox Code Playgroud)
但这本质上意味着每次我更新时,我都会重写整个pairs
字段(即使我只更新数组中的一个对象) - 这对我来说看起来不太理想还是可以?
归档时间: |
|
查看次数: |
14632 次 |
最近记录: |