在线Elasticsearch转Go Struct | 生成ES映射模型 - GoTool在线工具集

高效后端开发工具系列 - 指南与案例

😫 核心痛点

此工具提供 Elasticsearch 到 Go struct 代码的转换工具,能够自动解析 Elasticsearch 的 mapping 内容,并将其转换为 Go struct。该工具支持注入多重标签,确保生成的 struct 代码与 Elasticsearch 索引结构保持一致。旨在简化数据模型的映射和管理,提高开发效率,帮助开发者快速集成和使用 Elasticsearch 数据。。在实际开发中,这些琐碎的转换或配置工作往往消耗大量精力且容易引入错误。GoTool 为此提供了快速、准确且免费的在线解决方案。

💡 功能亮点 & 使用方案

功能介绍

1.将 mapping 中的 properties 内容转为 struct 如下:

{
	"mappings": {
		"properties": {
			"doc_id": {
				"type": "keyword"
			},
			"id": {
				"type": "long"
			},
			"path": {
				"type": "keyword"
			},
			"name": {
				"type": "text"
			},
			"url": {
				"type": "keyword"
			},
			"description": {
				"type": "text"
			},
			"created_time": {
				"type": "date",
				"format": "yyyy-MM-dd HH:mm:ss"
			}
		}
	}
}

处理后

type GenerateObj struct {
    DocId string `json:"doc_id,omitempty"`
    Id int64 `json:"id,omitempty"`
    Path string `json:"path,omitempty"`
    Name string `json:"name,omitempty"`
    Url string `json:"url,omitempty"`
    Description string `json:"description,omitempty"`
    CreatedTime string `json:"created_time,omitempty"`
}