ES将已有索引结构及数据拷贝到新索引

By | 2024 年 5 月 13 日

查询旧索引的结构详情

GET my_index
{
  "resource_index": {
    "aliases": {},
    "mappings": {
      "properties": {
        "IS_DELETED": {
          "type": "long"
        },
        "ecsSshPort": {
          "type": "float"
        },
        "globalCloudProjectID": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          },
          "fielddata": true
        },
        "globalConfigurationCode": {
          "type": "text",
          "analyzer": "caseSensitive"
        },
        "globalFirstLevel": {
          "type": "keyword"
        },
        "globalTag": {
          "type": "text",
          "analyzer": "tags_analyzer"
        },
        "rdsList": {
          "properties": {
            "DBInstanceDescription": {
              "type": "text",
              "fields": {
                "keyword": {
                  "type": "keyword",
                  "ignore_above": 256
                }
              }
            },
            "DBInstanceStatus": {
              "type": "long"
            },
            "ReadOnlyDBInstanceId": {
              "type": "object"
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "routing": {
          "allocation": {
            "include": {
              "_tier_preference": "data_content"
            }
          }
        },
        "mapping": {
          "total_fields": {
            "limit": "2000"
          }
        },
        "number_of_shards": "5",
        "provided_name": "resource_index",
        "max_result_window": "1000000",
        "creation_date": "1643186139977",
        "analysis": {
          "analyzer": {
            "tags_analyzer": {
              "lowercase": "false",
              "pattern": ";",
              "type": "pattern"
            },
            "caseSensitive": {
              "filter": "lowercase",
              "type": "custom",
              "tokenizer": "keyword"
            },
            "default": {
              "type": "keyword"
            }
          }
        },
        "number_of_replicas": "1",
        "uuid": "1_10JN9fTtKHJygzpQ7-qg",
        "version": {
          "created": "7150199"
        }
      }
    }
  }
}

创建索引,将原索引的settings和mappins拷贝到下方对应位置
因为新的索引用不到setting中的provided_name、creation_date、uuid、version.created等,复制到下方后将其剔除

PUT /my_index
{
  "settings": {
    ...
  },
  "mappings": {
    "properties": {
       ...
    }
  }
}

将原索引数据导入到新索引中

POST _reindex
{
  "source": {
    "index": "现有的索引名称",
    "size":1000,
    "query": {
      "match_all": {} 
    }
   },
  "dest": {
    "index": "新索引名称"
  }
}

成功返回结果,即新索引创建拷贝成功

{
  "took" : 319,
  "timed_out" : false,
  "total" : 7,
  "updated" : 0,
  "created" : 7,
  "deleted" : 0,
  "batches" : 1,
  "version_conflicts" : 0,
  "noops" : 0,
  "retries" : {
    "bulk" : 0,
    "search" : 0
  },
  "throttled_millis" : 0,
  "requests_per_second" : -1.0,
  "throttled_until_millis" : 0,
  "failures" : [ ]
}

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注