Elasticdump 是一个用于管理和迁移 Elasticsearch 和 OpenSearch 中数据的工具。Elasticdump 允许用户通过将数据导出到 JSON 文件并将其导入到其他地方来移动和保存索引。此功能对于备份和恢复目的以及在不同环境之间迁移数据(例如从开发到生产)特别有用。
现在,您也可以使用 Elasticdump 将您的 Elasticsearch/OpenSearch 索引导入到 Manticore。您可以选择两种可用选项之一:导入整个索引或仅导入其模式。
导入模式和数据
要将索引复制到 Manticore,包括数据,您可以使用以下命令:
elasticdump --input=http://localhost:9200/your_elasticsearch_or_opensearch_index --output=http://localhost:9308/your_manticore_table --type=data
让我们看一个使用它的简单示例。这里是名为 test 的原始 Elasticsearch 索引,其模式如下:
# curl -sX GET localhost:9200/test/_mapping
{
"test": {
"mappings": {
"properties": {
"price": {
"type": "float"
},
"title": {
“type": "text"
}
}
}
}
}
以及其中的 300 个文档:
# curl -sX GET localhost:9200/test/_count
{
"count": 300,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
}
}
到目前为止,我们在 Manticore 中没有任何表:
# curl -sX GET localhost:9308/cli -d 'SHOW TABLES'
Empty set (0.000 sec)
现在,让我们运行 Elasticdump:
# elasticdump --input=http://localhost:9200/test --output=http://localhost:9308/test_imported --type=data
Tue, 26 Feb 2024 16:18:52 GMT | starting dump
(node:156) [DEP0040] DeprecationWarning: The `punycode` module is deprecated. Please use a userland alternative instead.
(Use `node --trace-deprecation ...` to show where the warning was created)
Tue, 26 Feb 2024 16:18:52 GMT | got 300 objects from source elasticsearch (offset: 0)
Tue, 26 Feb 2024 16:18:52 GMT | sent 300 objects to destination elasticsearch, wrote 300
Tue, 26 Feb 2024 16:18:52 GMT | got 0 objects from source elasticsearch (offset: 300)
Tue, 26 Feb 2024 16:18:52 GMT | Total Writes: 300
Tue, 26 Feb 2024 16:18:52 GMT | dump complete
并检查我们所做的导入结果:
# curl -sX GET localhost:9308/cli -d 'DESC test_imported'
+-------+--------+----------------+
| Field | Type | Properties |
+-------+--------+----------------+
| id | bigint | |
| title | text | indexed stored |
| price | float | |
+-------+--------+----------------+
3 rows in set (0.000 sec)
# curl -sX GET localhost:9308/cli -d 'SELECT COUNT(*) FROM test_imported'
+----------+
| count(*) |
+----------+
| 300 |
+----------+
1 row in set (0.000 sec)
我们可以看到表已被复制。
仅导入模式
要仅导入表模式,请运行:
# elasticdump --input=http://localhost:9200/your_elasticsearch_or_opensearch_index --output=http://localhost:9308/your_manticore_table --type=mapping
您将获得一个新的空 Manticore 表,其结构从原始节点导入。
请注意,在上述示例中使用了默认的 Elasticsearch 和 Manticore 端口:localhost:9200 和 localhost:9308。如果您使用其他主机/端口连接到 Elasticsearch、OpenSearch 或 Manticore,您应相应地更改您的命令。
此外,请记住,Manticore 将某些 Elasticsearch 数据类型转换为其自己的数据类型,如果它在内部不支持这些类型:
aggregate_metric=>jsonbinary=>stringboolean=>boolbyte=>intcompletion=>stringdate=>timestampdate_nanos=>bigintdate_range=>jsondense_vector=>jsonflattened=>jsonflat_object=>jsonfloat=>floatfloat_range=>jsongeo_point=>jsongeo_shape=>jsonhalf_float=>floathistogram=>jsoninteger=>intinteger_range=>jsonip=>stringip_range=>jsonkeyword=>stringknn_vector=>float_vector,long=>bigintlong_range=>jsonmatch_only_text=>textobject=>jsonpoint=>jsonscaled_float=>floatsearch_as_you_type=>textshape=>jsonshort=>inttext=>textunsigned_long=>intversion=>string
例如,如果您按如下方式导入 Elasticsearch 索引:
{
"test": {
"mappings": {
"properties": {
"location": {
"type": "geo_point"
},
"title": {
"type": "text"
}
}
}
}
}
导入的 Manticore 表将具有以下模式:
+----------+--------+----------------+
| Field | Type | Properties |
+----------+--------+----------------+
| id | bigint | |
| title | text | indexed stored |
| location | json | |
+----------+--------+----------------+
结论
总之,Manticore Search 现在支持 Elasticdump,使用户更容易从 Elasticsearch 或 OpenSearch 迁移到 Manticore。此更新简化了迁移过程,使用户能够顺利传输数据和模式。这是希望在不麻烦复杂数据传输的情况下切换到 Manticore Search 的人的一个重要步骤。这一集成意味着一个简单的迁移,保持您的数据完整,使 Manticore Search 成为增强搜索能力的一个吸引人的选择。
