ElasticSearch在文档中移动节点



我有一个多个文档,它们有嵌套的对象。我需要移动文档中嵌套对象的位置。

我如何做到这一点,比如在下面的例子中将用户从组中移出:

{
"resourceGroup": "",
"abc": "Ok",
"firstSeen": "2020-03-16T08:45:02.444Z",
"entityId": "29e7d555-1959-4b9b-b663-ce0d04f3e5a7",
"type": "GroupEntity",
"group": {
"onPremisesProvisioningErrors": ,
"mailNickname": "74b06328-1",
"users": [
{
"mail": "abc@aaa.com",
"mailNickname": "sdf"
},
{
"displayName": "test user",
"mailNickname": "testuser1"
}
],
}
}

您可以使用摄取节点

在实际文档索引发生之前,使用摄取节点预处理文档。摄取节点截获批量和索引请求,应用转换,然后将文档传递回索引或批量API。

样本映射

PUT index54
{
"mappings": {
"properties": {
"resourceGroup": {
"type": "text"
},
"group": {
"type": "object",
"properties": {
"users": {
"type": "nested",
"properties": {
"mail": {
"type": "text"
},
"mailNickname": {
"type": "text"
}
}
}
}
}
}
}
}

Ingest Pipeline

PUT _ingest/pipeline/moveuserspropertypipeline
{
"description" : "move users out of group",
"processors" : [
{
"set" : {
"field": "users",
"value": "{{group.users}}"
}
},
{
"remove": {
"field": "group.users"
}
}
]
}

使用重新索引API文档可以从源索引复制到新索引。在执行重新索引api 之前,使用正确的映射创建目标索引

POST _reindex
{
"source": {
"index": "index54"
},
"dest": {
"index": "index55",
"pipeline": "moveuserspropertypipeline"
}
}

最新更新