es生产索引升级实践-索引重建以及索引别名

本文介绍两种索引升级的方法:一种是通过重建索引来完成升级,包括创建临时索引、迁移数据及验证等步骤;另一种是利用别名实现索引的无感知升级,涉及创建新索引、备份旧数据、切换别名等过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

索引升级

方案一,索引重建:

PUT /ads_iot_water_index_temp
{
    "mappings": {
        "_doc": {
            "dynamic": "strict",
        "properties" : {
          "cnts" : {
            "type" : "float"
          },
          "dh" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "dm" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "dt" : {
            "type" : "date"
          },
          "equipmentNo" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "meterVarId" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "name" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "pk" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "projectIdentify" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "t_start" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss"
          },
          "type_" : {
            "type" : "long"
          },
          "unit" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
        }
    }
}


POST _reindex
{
"source": {
"index":"ads_iot_water_index"
},
"dest": {
"index":"ads_iot_water_index_temp"
}
}

GET /ads_iot_water_index_temp
GET /ads_iot_water_index/_doc/_search
GET /ads_iot_water_index_temp/_doc/_search

POST _xpack/sql?format=txt
{
  "query":"select * from ads_iot_water_index_temp where t_start between '2021-01-25 00:00:00' and '2021-01-25 05:00:00'"
}

#### 还原数据

DELETE /ads_iot_water_index

PUT /ads_iot_water_index
{
    "mappings": {
        "_doc": {
            "dynamic": "strict",
        "properties" : {
          "cnts" : {
            "type" : "float"
          },
          "dh" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "dm" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "dt" : {
            "type" : "date"
          },
          "equipmentNo" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "meterVarId" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "name" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "pk" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "projectIdentify" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          },
          "t_start" : {
            "type" : "date",
            "format" : "yyyy-MM-dd HH:mm:ss"
          },
          "type_" : {
            "type" : "long"
          },
          "unit" : {
            "type" : "text",
            "fields" : {
              "keyword" : {
                "type" : "keyword",
                "ignore_above" : 256
              }
            }
          }
        }
        }
    }
}

POST _reindex
{
"source": {
"index":"ads_iot_water_index_temp"
},
"dest": {
"index":"ads_iot_water_index"
}
}

POST _xpack/sql?format=txt
{
  "query":"select * from ads_iot_water_index where t_start between '2021-01-25 06:00:00' and '2021-01-25 10:00:00'"
}

方案二,索引对外使用别名,无感知升级:

PUT /iot_ads_x_hour_inner
{
    "mappings": {
        "_doc": {
            "dynamic": "strict",
            "properties": {
                "avg": {
                    "type": "float"
                },
                "dh": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "dm": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "dt": {
                    "type": "date"
                },
                "equipmentNo": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "frequency": {
                    "type": "long"
                },
                "last_update_time": {
                    "format": "yyyy-MM-dd HH:mm:ss",
                    "type": "date"
                },
                "max_dataValue": {
                    "type": "float"
                },
                "meterKind": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "meterVarId": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "min_dataValue": {
                    "type": "float"
                },
                "name": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "pk": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "projectIdentify": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "span": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                },
                "t_start": {
                    "format": "yyyy-MM-dd HH:mm:ss",
                    "type": "date"
                },
                "total_cnts": {
                    "type": "float"
                },
                "type": {
                    "fields": {
                        "keyword": {
                            "ignore_above": 256,
                            "type": "keyword"
                        }
                    },
                    "type": "text"
                }
            }
        }
    }
}

#备份
POST _reindex?slices=9&refresh&wait_for_completion=false
{
  "source": {"index": "iot_ads_x_hour",
    "size": 10000
  }
  , "dest": {"index": "iot_ads_x_hour_inner"}
}

#删

#别名
POST _aliases
{"actions": [
  {
    "add": {
      "index": "iot_ads_x_hour_inner",
      "alias": "iot_ads_x_hour"
    }
  }
]}

# 删别名
POST _aliases
{"actions": [
  {
    "remove": {"index": "iot_ads_x_hour_inner","alias": "iot_ads_x_hour"}
  }
]}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值