zoukankan      html  css  js  c++  java
  • es之重建索引

    1.为什么需要重建索引

      举个例子,如果一个字段是text类型,如果想修改为Long类型,是不能直接修改的。

      在重建的过程中,需要有别名的参与。

    2.操作步骤

      对当前的索引新建一个别名

      新建一个新的索引,同步结构

      同步数据

      给新的索引见一个别名

      删除老的索引的别名

      删除老的索引

    二:操作步骤详解

    1.对当前的索引添加别名

    POST /_aliases
    {
      "actions": [
        {
          "add": {
            "index": "nba",
            "alias": "nba_lastest"
          }
        }
      ]
    }
    

      

    2.新增⼀个索引(⽐如修改字段类型,jerseyNo改成keyword类型)

    PUT /nba_20200202
    {
      "mappings": {
        "properties": {
            "age" : {
              "type" : "integer"
            },
            "birthDay" : {
              "type" : "date"
            },
            "birthDayStr" : {
              "type" : "keyword"
            },
            "code" : {
              "type" : "text"
            },
            "country" : {
              "type" : "text"
            },
            "countryEn" : {
              "type" : "text"
            },
            "displayAffiliation" : {
              "type" : "text"
            },
            "displayName" : {
              "type" : "text"
            },
            "displayNameEn" : {
              "type" : "text"
            },
            "draft" : {
              "type" : "long"
            },
            "heightValue" : {
              "type" : "float"
            },
            "jerseyNo" : {
              "type" : "keyword"
            },
            "playYear" : {
              "type" : "long"
            },
            "playerId" : {
              "type" : "keyword"
            },
            "position" : {
              "type" : "text"
            },
            "schoolType" : {
              "type" : "text"
            },
            "teamCity" : {
              "type" : "text"
            },
            "teamCityEn" : {
              "type" : "text"
            },
            "teamConference" : {
              "type" : "keyword"
            },
            "teamConferenceEn" : {
              "type" : "keyword"
            },
            "teamName" : {
              "type" : "keyword"
            },
            "teamNameEn" : {
              "type" : "keyword"
            },
            "weight" : {
              "type" : "text"
            }
          }
      }
    }
    

      

    3.给新的索引,同步数据

      添加的参数,是异步执行的意思

    POST /_reindex?wait_for_completion=false
    {
      "source": {
        "index": "nba"
      },
      "dest": {
        "index": "nba_20200202"
      }
    }
    

      效果:

    {
      "task" : "O9L9cZRfQwWqC2UVUaxMaQ:18594274"
    }
    

      

    4.替换别名

    POST /_aliases
    {
      "actions": [
        {
          "add": {
            "index": "nba_20200202",
            "alias": "nba_lastest"
          }
        },
        {
          "remove": {
            "index": "nba",
            "alias": "nba_lastest"
          }
        }
      ]
    }
    

      

    5.删除旧的索引

      其实,这里不删除也行,但是会占用一些资源

    DELETE /nba
    

      

    6.进行验证

    GET /nba_lastest/_search
    {
      "query": {
        "match_all": {}
      }
    }
    

      

  • 相关阅读:
    [BZOJ2763] [JLOI2011] 飞行路线
    [BZOJ4033] [HAOI2015] 树上染色
    [BZOJ2565] 最长双回文串
    [luogu5048] [Ynoi2019模拟赛] Yuno loves sqrt technology III
    又犯了低级错误了
    Win10系统无法使用小米手机的远程管理功能
    DevExpress破解和消除弹出框问题
    重写导致的问题
    EXCEL统计不重复值的数量
    C#中Button.DialogResult属性
  • 原文地址:https://www.cnblogs.com/juncaoit/p/12815582.html
Copyright © 2011-2022 走看看