使用reindex API来将现有索引重新索引到一个新索引中并指定所需的分片数。es的版本为7.13.2如何操作?
时间: 2024-05-26 14:12:28 浏览: 17
您可以按照以下步骤操作:
1.打开Kibana控制台,并选择Dev Tools.
2.向新索引设置映射。这是为确保旧索引和新索引的映射类型相同。例如:
POST /new_index/_mapping
{
"properties": {
"field1": {
"type": "text"
},
"field2": {
"type": "float"
}
}
}
3.通过_reindex API 将旧索引重新索引到新索引。例如:
POST _reindex
{
"source": {
"index": "old_index"
},
"dest": {
"index": "new_index"
},
"conflicts": "proceed",
"size": 1000
}
其中,source指定要重建索引的旧索引,dest指定新索引的名称,并且conflicts表示在存在冲突的情况下控制行为。size参数指定每次请求的文档数。
4.您可以使用以下命令的部分来调整新索引的分片数:
PUT new_index/_settings
{
"index": {
"number_of_shards": 6
}
}
这会将新索引设置为6个分片。请注意,此操作需要重新索引所有现有文档。
相关问题
使用reindex API来将现有索引重新索引到一个新索引中并指定所需的分片数。如何操作?
要使用reindex API将现有索引重新索引到一个新索引中并指定所需的分片数,可以按照以下步骤进行操作:
1.使用reindex API创建一个新索引,并指定所需的分片数。
例如,使用以下命令在一个名为 new_index 的新索引中创建一个具有 3 个分片的索引:
```
POST /_reindex
{
"source": {
"index": "old_index"
},
"dest": {
"index": "new_index",
"shards": 3
}
}
```
注意,这个命令是在 Kibana 中执行的,其中 old_index 是现有索引的名称。
2.等待索引重新索引完成。
当重新索引操作正在进行时,可以使用 _cat/reindex API 检查进度,例如:
```
GET _cat/reindex?v
```
这会显示在进行中的重新索引操作的详细信息,包括进度和分片分配情况。
3.使用新索引。
当重新索引操作完成后,可以将查询和其他操作指向新索引,例如:
```
GET new_index/_search
```
这将从新索引中检索数据。
注意,此操作不会删除旧索引,需要手动删除。
elasticsearch 8版本如何把索引传输到另外一个elasticsearch集群?不适用快照方法
您可以使用以下方法将索引从一个Elasticsearch集群传输到另一个集群,而不使用快照方法:
1. 导出索引数据:
- 使用 Elasticsearch 提供的 `_reindex` API 将索引数据导出为 JSON 文件。
- 使用 Elasticsearch 的 `scroll` API 和 `search` API 逐批获取索引数据,并将数据保存为 JSON 文件。
2. 导入索引数据:
- 在目标集群上创建空索引,具有与源索引相同的映射设置。
- 使用 Elasticsearch 的 `bulk` API 或 `index` API 将之前导出的 JSON 文件中的数据批量导入到目标索引。
以下是具体的步骤:
1. 导出索引数据:
- 使用 `_reindex` API 的 `source` 参数指定源索引的名称和集群。
- 使用 `_reindex` API 的 `dest` 参数指定目标索引的名称和集群。
- 使用 `_reindex` API 的 `wait_for_completion=false` 参数来异步执行导出操作。
示例请求:
```bash
POST _reindex
{
"source": {
"index": "source_index",
"remote": {
"host": "http://source_cluster_host:9200"
}
},
"dest": {
"index": "target_index",
"remote": {
"host": "http://target_cluster_host:9200"
}
},
"wait_for_completion": false
}
```
2. 导入索引数据:
- 在目标集群上创建空索引,与源索引具有相同的映射设置。
- 使用 Elasticsearch 的 `bulk` API 或 `index` API 将之前导出的 JSON 文件中的数据批量导入到目标索引。
示例请求:
```bash
POST target_index/_bulk
{ "index": { "_index": "target_index", "_id": "1" }}
{ "field1": "value1" }
{ "index": { "_index": "target_index", "_id": "2" }}
{ "field1": "value2" }
```
请注意,这种方法可能会导致一些数据丢失或不一致,因为数据传输过程中可能发生变化。使用快照和还原是更可靠和一致的方法,但如果您不适用快照方法,可以尝试上述步骤。确保在生产环境中进行充分测试,并备份数据以防止意外情况发生。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)