我正在尝试更新子文档并将其添加到父文档中值存在的新字段。 elasticsearch
npm lib完成的所有操作。查询如下:
var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
host: 'localhost:9200',
// log: 'trace'
});
const getAllChatsQuery = {
scroll: '10s',
body: {
query: {
has_parent: {
parent_type: "chat",
query: {
match_all: {}
},
inner_hits: {
}
}
}
}
};
let allRecords = []
function f() {
try {
client.search(
getAllChatsQuery, function fetchResults(err, results) {
console.log(results)
for (let chat of results.hits.hits) {
for (let msg of chat.inner_hits.chat.hits.hits){
console.log(msg)
}
console.log(chat.inner_hits.chat.hits.hits)
console.log(chat)
allRecords.push(chat)
}
if (results.hits.total !== allRecords.length) {
client.scroll({
scrollId: results._scroll_id,
scroll: '10s'
}, fetchResults);
} else {
// console.log('all done', allRecords);
console.log('all done', allRecords.length);
}
});
} catch (error) {
console.trace(error.message)
}
}
f()
现在我想知道是否可以使用一个查询将parent._source.service
复制到child._source
中?或者我必须运行与搜索查询分开的更新查询
谢谢
现在我的主要问题是可以选择更新