Reindex真题1

题目

reindex+ingest_pipeline,难点是其中有一个字段是数组,数组的内容大概如下: text: ' abcedf ds ' ' 123abc' ' abc123' ' cde123' } reindex的时候,需要去掉数组前后的空格,然后要新增一个field,fullname= firstname + lastname

添加pipeline

PUT _ingest/pipeline/ig2
{
  "description": "",
  "processors": [
    {
      "set": {
        "field": "fullname",
        "value": "{{firstname}} {{lastname}}"
      },
      "foreach": {
        "field": "foo",
        "processor": {
          "trim": {
            "field": "_ingest._value"
          }
        }
      }
    }
  ]
}

测试pipeline

POST _ingest/pipeline/ig2/_simulate
{
  "docs": [
    {
      "_source": {
        "foo": [
          " adsa 123 ",
          " 21232 321"
        ],
        "firstname": "Li",
        "lastname": "xiaolong"
      }
    }
  ]
}

执行Reindex

PUT test_1/_bulk
{"index":{"_index":"test_1","_id":0}}
{"foo":[" adsa 123 "," 21232 321"],"firstname":"Li","lastname":"xiaolong"}

POST _reindex
{
  "source": {
    "index": "test_1"
  },
  "dest": {
    "index": "test_2",
    "pipeline": "ig2"
  }
}

测试Reindex结果

GET test_2/_search

总结

  • Reindex可以使用pipeline或者script
  • pipeline的编写可以使用内置的processor,也可以直接使用脚本
  • ingest pipeline 优先使用内置的processor
  • 如果写脚本,使用"""三重双引号

你可能感兴趣的:(Reindex真题1)