Amazon web services ElasticSearch使用选定字段重新编制索引,结果添加到未选定的空字段中
场景:Amazon web services ElasticSearch使用选定字段重新编制索引,结果添加到未选定的空字段中,amazon-web-services,elasticsearch,kibana,elastic-stack,Amazon Web Services,elasticsearch,Kibana,Elastic Stack,场景: { "userdata": { "properties": { "payload": { "type": "object", "properties": { "Alldata": { "Userna
{
"userdata": {
"properties": {
"payload": {
"type": "object",
"properties": {
"Alldata": {
"Username": {
"type": "keyword"
},
"Designation": {
"type": "keyword"
},
"Company": {
"type": "keyword"
},
"Region": {
"type": "keyword"
}
}
}
}
}
}}
我们正在使用AWS ElasticSearch 6.8。我们得到了一个索引(index-A),其映射结构由多个嵌套对象和JSON层次结构组成。我们需要创建新索引(index-B),并将所有文档从index-A移动到index-B
- 我们需要创建只包含特定字段的索引-B
- 我们需要在重新编制索引时重命名字段名
{
"userdata": {
"properties": {
"payload": {
"type": "object",
"properties": {
"Alldata": {
"Username": {
"type": "keyword"
},
"Designation": {
"type": "keyword"
},
"Company": {
"type": "keyword"
},
"Region": {
"type": "keyword"
}
}
}
}
}
}}
使用重命名重新编制索引后索引B映射的预期结构(公司cnm,区域rg):-
我们正在遵循的步骤:
{
"userdata": {
"properties": {
"payload": {
"type": "object",
"properties": {
"Alldata": {
"Username": {
"type": "keyword"
},
"Designation": {
"type": "keyword"
},
"Company": {
"type": "keyword"
},
"Region": {
"type": "keyword"
}
}
}
}
}
}}
{
"description": "rename field pipeline",
"processors": [{
"rename": {
"field": "payload.Company",
"target_field": "cnm",
"ignore_missing": true
}
},
{
"rename": {
"field": "payload.Region",
"target_field": "rg",
"ignore_missing": true
}
}
]
}
let reindexParams = {
wait_for_completion: false,
slices: "auto",
body: {
"conflicts": "proceed",
"source": {
"size": 8000,
"index": "index-A",
"_source": ["payload.Company", "payload.Region"]
},
"dest": {
"index": "index-B",
"pipeline": "my_rename_pipeline",
"version_type": "external"
}
}
};
{
"userdata": {
"properties": {
"payload": {
"type": "object",
"properties": {
"Alldata": {
"Username": {
"type": "keyword"
},
"Designation": {
"type": "keyword"
},
"Company": {
"type": "keyword"
},
"Region": {
"type": "keyword"
}
}
}
}
}
}}
一旦按预期完成重新编制索引,所有文档都将传输到新索引,并重命名了字段,但还有一个字段未选中。正如您在下面看到的,在重新编制索引后,带有元数据的“payload”对象也被添加到新索引中。此字段为空,不包含任何数据
重新编制索引后,索引B如下所示:
{
"userdata": {
"properties": {
"cnm": {
"type": "keyword"
},
"rg": {
"type": "keyword"
},
"payload": {
"properties": {
"Alldata": {
"type": "object"
}
}
}
}
}}
我们无法找到解决方法,需要帮助如何阻止此字段创建。任何帮助都将不胜感激。干得好!!您就快到了,只需使用删除管道中的
有效负载
字段即可:
{
"description": "rename field pipeline",
"processors": [
{
"rename": {
"field": "payload.Company",
"target_field": "cnm",
"ignore_missing": true
}
},
{
"rename": {
"field": "payload.Region",
"target_field": "rg",
"ignore_missing": true
}
},
{
"remove": { <--- add this processor
"field": "payload"
}
}
]
}
{
“说明”:“重命名字段管道”,
“处理器”:[
{
“重命名”:{
“字段”:“有效载荷.公司”,
“目标_字段”:“cnm”,
“忽略缺失”:真
}
},
{
“重命名”:{
“字段”:“有效负载区域”,
“目标_字段”:“rg”,
“忽略缺失”:真
}
},
{
“删除”:{这方面运气好吗?