前言

  • 本文对 Elasticsearch 7.17 适用
  • 需要通过 reindex 给数据添加字段,查官方文档估摸 setappend 两种 processor 实现,试验之

试验过程

idx_1

  • 创建索引 idx_1
POST idx_1/_doc/1
{
  "author": "qbit"
}

idx_2

  • 运用 set 创建 pipeline
PUT _ingest/pipeline/addtag
{
  "processors" : [
    {
      "set" : {
        "field" : "tag",
        "value": "set"
      }
    }
  ]
}
  • 创建索引 idx_2
POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "idx_1",
    "size": 5000            
  },
  "dest": {
    "index": "idx_2",  
    "pipeline": "addtag"
  }
}
  • 查看索引 idx_2
GET idx_2/_search
{
    "_index" : "idx_2",
    "_type" : "_doc",
    "_id" : "1",
    "_score" : 1.0,
    "_source" : {
      "author" : "qbit",
      "tag" : "set"
    }
}

idx_3

  • 运用 append 创建 pipeline
PUT _ingest/pipeline/appendtag
{
  "processors" : [
    {
      "append" : {
        "field" : "tag",
        "value": "append"
      }
    }
  ]
}
  • 创建索引 idx_3
POST _reindex?wait_for_completion=false
{
  "source": {
    "index": "idx_2",
    "size": 5000            
  },
  "dest": {
    "index": "idx_3",  
    "pipeline": "appendtag"
  }
}
  • 查看索引 idx_3
GET idx_3/_search
{
  "_index" : "idx_3",
  "_type" : "_doc",
  "_id" : "1",
  "_score" : 1.0,
  "_source" : {
    "author" : "qbit",
    "tag" : [
      "set",
      "append"
    ]
  }
}

相关阅读

本文出自 qbit snap

qbit
268 声望279 粉丝