mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-04 23:52:53 +08:00
use auto ceate index
This commit is contained in:
@@ -4,7 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/lzh-1625/go_process_manager/config"
|
"github.com/lzh-1625/go_process_manager/config"
|
||||||
@@ -124,28 +123,3 @@ func (e *esSearch) Search(req model.GetLogReq, filterProcessName ...string) mode
|
|||||||
result.Total = resp.TotalHits()
|
result.Total = resp.TotalHits()
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// 通过反射得到mapping
|
|
||||||
func (e *esSearch) structToJSON() string {
|
|
||||||
typ := reflect.TypeOf(model.ProcessLog{})
|
|
||||||
properties := make(map[string]map[string]string)
|
|
||||||
for i := 0; i < typ.NumField(); i++ {
|
|
||||||
field := typ.Field(i)
|
|
||||||
fieldTag := field.Tag.Get("type")
|
|
||||||
if fieldTag != "" {
|
|
||||||
properties[field.Tag.Get("json")] = map[string]string{
|
|
||||||
"type": fieldTag,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result := map[string]interface{}{
|
|
||||||
"mappings": map[string]interface{}{
|
|
||||||
"properties": properties,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
jsonData, err := json.Marshal(result)
|
|
||||||
if err != nil {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
return string(jsonData)
|
|
||||||
}
|
|
||||||
|
Reference in New Issue
Block a user