⚠️ 此页面为自动翻译,翻译可能不完美。
blog-post

How to use Elasticdump with Manticore

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:9200localhost:9308。如果您使用其他主机/端口连接到 Elasticsearch、OpenSearch 或 Manticore,请相应地更改命令。

此外,请记住,Manticore 会将某些 Elasticsearch 数据类型转换为它自己的类型,如果它不支持这些类型:

  • aggregate_metric => json
  • binary => string
  • boolean => bool
  • byte => int
  • completion => string
  • date => timestamp
  • date_nanos => bigint
  • date_range => json
  • dense_vector => json
  • flattened => json
  • flat_object => json
  • float => float
  • float_range => json
  • geo_point => json
  • geo_shape => json
  • half_float => float
  • histogram => json
  • integer => int
  • integer_range => json
  • ip => string
  • ip_range => json
  • keyword => string
  • knn_vector => float_vector,
  • long => bigint
  • long_range => json
  • match_only_text => text
  • object => json
  • point => json
  • scaled_float => float
  • search_as_you_type => text
  • shape => json
  • short => int
  • text => text
  • unsigned_long => int
  • version => 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 成为轻松增强搜索功能的有吸引力的选择。

安装Manticore Search

安装Manticore Search