-- --
⎯⎯ 对未来真正的慷慨就是把一切都献给现在

--

 0  |   |   0

0/

     
说 明

elasticsearch转struct



功能介绍

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