假设我有以下示例索引和示例文档。
样本来源索引
为了便于理解,我创建了以下映射。
PUT my_source_index
{
"mappings": {
"properties": {
"email":{
"type":"text"
},
"name":{
"type": "text"
}
}
}
}
示例文档:
POST my_source_index/_doc/1
{
"email": ["john@gmail.com","doe@outlook.com"],
"name": "johndoe"
}
只需按照以下步骤操作
第 1 步:创建摄取管道
PUT _ingest/pipeline/my-pipeline-concat
{
"description" : "describe pipeline",
"processors" : [
{
"join": {
"field": "email",
"target_field": "temp_uuid",
"separator": "-"
}
},
{
"set": {
"field": "uuid",
"value": "{{name}}-{{temp_uuid}}"
}
},
{
"remove":{
"field": "temp_uuid"
}
}
]
}
请注意,我使用了Ingest API,其中我使用了三个processors,而creating the above pipeline 将按顺序执行:
请注意,我使用- 作为所有值之间的分隔符。你可以随意使用任何你想要的东西。
第 2 步:创建目标索引:
PUT my_dest_index
{
"mappings": {
"properties": {
"email":{
"type":"text"
},
"name":{
"type": "text"
},
"uuid":{ <--- Do not forget to add this
"type": "text"
}
}
}
}
第 3 步:应用重新索引 API:
POST _reindex
{
"source": {
"index": "my_source_index"
},
"dest": {
"index": "my_dest_index",
"pipeline": "my-pipeline-concat" <--- Make sure you add pipeline here
}
}
注意我在使用 Reindex API 时是如何提到管道的
第 4 步:验证目标索引:
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "my_dest_index",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"name" : "johndoe",
"uuid" : "johndoe-john@gmail.com-doe@outlook.com", <--- Note this
"email" : [
"john@gmail.com",
"doe@outlook.com"
]
}
}
]
}
}
希望这会有所帮助!