GO在线工具集
首页
搜索
反馈
【店小二】公告:

es转struct
1691  |   |   |  2

功能介绍

1.将 mapping 中的 properties 内容转为 struct 2.注意是将 properties 值作为输入内容, 如下:

{
    "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"
            }
        }
    }
}

示例

{
    "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"`
}