mirror of
https://github.com/lzh-1625/go_process_manager.git
synced 2025-10-06 00:16:53 +08:00
use auto ceate index
This commit is contained in:
@@ -3,7 +3,6 @@ package es
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"reflect"
|
"reflect"
|
||||||
"time"
|
"time"
|
||||||
@@ -41,7 +40,6 @@ func (e *esSearch) Init() error {
|
|||||||
log.Logger.Warnw("Failed to connect to es", "err", err)
|
log.Logger.Warnw("Failed to connect to es", "err", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
e.CreateIndexIfNotExists(config.CF.EsIndex)
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,27 +56,6 @@ func (e *esSearch) Insert(logContent string, processName string, using string, t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *esSearch) CreateIndexIfNotExists(index string) error {
|
|
||||||
|
|
||||||
ctx := context.Background()
|
|
||||||
exists, err := e.esClient.IndexExists(index).Do(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if exists {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
info, err := e.esClient.CreateIndex(index).BodyString(e.structToJSON()).Do(ctx)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if !info.Acknowledged {
|
|
||||||
return fmt.Errorf("ES 创建索引 [%s] 失败", index)
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *esSearch) Search(req model.GetLogReq, filterProcessName ...string) model.LogResp {
|
func (e *esSearch) Search(req model.GetLogReq, filterProcessName ...string) model.LogResp {
|
||||||
// 检查 req 是否为 nil
|
// 检查 req 是否为 nil
|
||||||
if req.Page.From < 0 || req.Page.Size <= 0 {
|
if req.Page.From < 0 || req.Page.Size <= 0 {
|
||||||
|
Reference in New Issue
Block a user