2

我在 ElasticSearch 中有一个包含映射和数据的现有索引,我需要复制这些索引以测试新开发。无论如何要从已经存在的索引中创建一个临时/重复索引?

来自 SQL 背景,我正在寻找相当于

SELECT * 
INTO TestIndex
FROM OriginalIndex
WHERE 1 = 0

我已经尝试过Clone API,但无法让它工作。

我正在尝试使用以下方法进行克隆:

POST /originalindex/_clone/testindex
{
}

但这会导致以下异常:

{
  "error": {
    "root_cause": [
      {
        "type": "invalid_type_name_exception",
        "reason": "Document mapping type name can't start with '_', found: [_clone]"
      }
    ],
    "type": "invalid_type_name_exception",
    "reason": "Document mapping type name can't start with '_', found: [_clone]"
  },
  "status": 400
}

我知道有人会很快指导我。在此先感谢你们所有了不起的人。

4

2 回答 2

1

首先,您必须将源索引设置为只读

PUT /originalindex/_settings
{
  "settings": {
    "index.blocks.write": true
  }
}

然后你可以克隆

POST /originalindex/_clone/testindex

如果需要将文档复制到新索引,可以使用reindex api

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: 
application/json' -d'
{
  "source": {
    "index": "someindex"
  },
  "dest": {
    "index": "someindex_copy"
  }
}
'

(参见:https ://wrossmann.medium.com/clone-an-elasticsearch-index-b3e9b295d3e9 )

于 2020-12-28T04:21:36.923 回答
1

发布问题后不久,我想出了一个方法。

首先,获取原始索引的属性:

GET originalindex

复制属性并放入新索引:

PUT /testindex
{
    "aliases": {...from the above GET request},
    "mappings": {...from the above GET request},
    "settings": {...from the above GET request}
}

现在我有了一个新的测试索引。

于 2020-12-28T04:22:21.977 回答