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#实战Microsoft Messaging Queue(MSMQ)
    Spring注解用法
    Last_IO_Errno: 1032
    浅谈TCP/IP网络编程中socket的行为
    Golang网络库中socket阻塞调度源码剖析
    delphi新语法之泛型实现的对象池模板
    Delphi 编码转换 Unicode gbk big5(使用LCMapString设置区域后,再用API转换)
    提高Delphi的编译速度(bpl和bcp)
    解决jqplot与jquery-ui导入必要包时的冲突
    Linux系统下用C语言获取MAC地址
  • 原文地址:https://www.cnblogs.com/juncaoit/p/12815582.html
Copyright © 2011-2022 走看看