blog-post

如何使用 Elasticdump 与 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'

空集 (0.000 秒)

现在,让我们运行 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