Reindex For Elastic ( Version 7.6 )

如果你也是将 Elastic 当作搜寻快取再使用的话,一定也会常常碰到一些情况需要 Reindex。

我们一开始在使用的时候常碰到几个问题,Logstash 没指定 db 栏位的 type,到了 elastic 上后结果跟预期不符,或是 db / elastic 上的资料不一致等等问题,这时候我们需要的就是 reindex。

以下就是 reindex 的步骤与一些注意事项。

先开新的 index 假设叫做 member,后面我们加上版本号 member_version_1

PUT /member_verison_1 {}

如果有需要可以先指定 field 的 type

PUT /member_verison_1/_mapping{    "properties": {      "height": {        "type": "short"      }    }}

在 reindex 的时候就不要 copy 这栏的资料,用 ingest node 搭配 pipeline

先新增 ingest node

PUT _ingest/pipeline/pass_height{  "description": "Removes the 'height' field",  "processors": [    {      "remove": {        "field": ["height"],        "ignore_missing": true      }    }  ]}

官网相关说明

準备 OK 开始 reindex

POST _reindex?wait_for_completion=false{  "source": {    "index": "member"  },  "dest": {    "index": "member_version_1",    "pipeline": "height_error"  }}

通常 reindex 都需要一段时间为避免 timeout 加上 wait_for_completion,会回传 task 的 id,可以在用 task 查询 reindex 的状况。

GET /_tasks/HSEnIEfuTaCLI-V7bRj3lg:17533795

接下来要设定 alias,如果原本的 index 就叫 member 没有加上 version 的话,我们就只能先删掉原本的 index,再加上 alias

DELETE /member

加上 alias

PUT /member_version_1/_alias/member

如果原本就有设定 alias 的话要先移除

POST /_aliases{    "actions" : [        { "remove" : { "index" : "member_version_1", "alias" : "member" } }    ]}

结束,以上就是尽可能平滑无痛 reindex 的步骤,透过 alias 的方式,基本上对前端查询不会有什么影响,就算要花一段时间重建也不用担心啰!


关于作者: 网站小编

码农网专注IT技术教程资源分享平台,学习资源下载网站,58码农网包含计算机技术、网站程序源码下载、编程技术论坛、互联网资源下载等产品服务,提供原创、优质、完整内容的专业码农交流分享平台。

热门文章