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": {}
      }
    }
    

      

  • 相关阅读:
    植物大战僵尸 辅助 总结
    C# 操作地址 从内存中读取写入数据(初级)
    c# math
    c# 获取屏幕图片
    从客户端(editorValue="<p>xxxx</p>")中检测到有潜在危险的 Request.Form 值。
    三种常见的SQL分页语句
    Windows Installer 服务无法启动!
    无法访问windows installer服务
    mssql2000数据库执行SQL语句来创建数据库以及数据表还有索引
    如何安装aspjpeg
  • 原文地址:https://www.cnblogs.com/juncaoit/p/12815582.html
Copyright © 2011-2022 走看看