refactor
This commit is contained in:
parent
f63a70126d
commit
e58c2412af
|
@ -1,7 +1,6 @@
|
||||||
package index_management
|
package index_management
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -27,17 +26,20 @@ func (handler APIHandler) HandleAddDocumentAction(w http.ResponseWriter, req *ht
|
||||||
resResult := newResponseBody()
|
resResult := newResponseBody()
|
||||||
err := handler.DecodeJSON(req, &reqBody)
|
err := handler.DecodeJSON(req, &reqBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E10001"
|
resResult["status"] = false
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["error"] = err.Error()
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
indexName := ps.ByName("index")
|
indexName := ps.ByName("index")
|
||||||
id := util.GetUUID()
|
id := ps.ByName("id")
|
||||||
|
if strings.Trim(id, "/") == "" {
|
||||||
|
util.GetUUID()
|
||||||
|
}
|
||||||
_, err = client.Index(indexName, id, reqBody)
|
_, err = client.Index(indexName, id, reqBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E10002"
|
resResult["status"] = false
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["error"] = err
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -52,8 +54,8 @@ func (handler APIHandler) HandleUpdateDocumentAction(w http.ResponseWriter, req
|
||||||
resResult := newResponseBody()
|
resResult := newResponseBody()
|
||||||
err := handler.DecodeJSON(req, &reqBody)
|
err := handler.DecodeJSON(req, &reqBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E10001"
|
resResult["status"] = false
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["error"] = err
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -61,8 +63,8 @@ func (handler APIHandler) HandleUpdateDocumentAction(w http.ResponseWriter, req
|
||||||
id := ps.ByName("id")
|
id := ps.ByName("id")
|
||||||
resp, err := client.Get(indexName, id)
|
resp, err := client.Get(indexName, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E10004"
|
resResult["status"] = false
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["error"] = err.Error()
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -72,8 +74,8 @@ func (handler APIHandler) HandleUpdateDocumentAction(w http.ResponseWriter, req
|
||||||
}
|
}
|
||||||
_, err = client.Index(indexName, id, source)
|
_, err = client.Index(indexName, id, source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E10005"
|
resResult["status"] = false
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["error"] = err.Error()
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -88,8 +90,8 @@ func (handler APIHandler) HandleDeleteDocumentAction(w http.ResponseWriter, req
|
||||||
id := ps.ByName("id")
|
id := ps.ByName("id")
|
||||||
_, err := client.Delete(indexName, id)
|
_, err := client.Delete(indexName, id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["error"] = err.Error()
|
||||||
resResult["errno"] = "E10006"
|
resResult["status"] = false
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -102,8 +104,8 @@ func (handler APIHandler) HandleSearchDocumentAction(w http.ResponseWriter, req
|
||||||
resResult := newResponseBody()
|
resResult := newResponseBody()
|
||||||
err := handler.DecodeJSON(req, &reqBody)
|
err := handler.DecodeJSON(req, &reqBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E10001"
|
resResult["status"] = false
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["error"] = err.Error()
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -139,65 +141,18 @@ func (handler APIHandler) HandleSearchDocumentAction(w http.ResponseWriter, req
|
||||||
var reqBytes = []byte(query)
|
var reqBytes = []byte(query)
|
||||||
resp, err := client.SearchWithRawQueryDSL(indexName, reqBytes)
|
resp, err := client.SearchWithRawQueryDSL(indexName, reqBytes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E10007"
|
resResult["status"] = false
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["error"] = err.Error()
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
result := formatESSearchResult(resp)
|
//result := formatESSearchResult(resp)
|
||||||
|
|
||||||
_, _, idxs, err := client.GetMapping(false, indexName)
|
resResult["payload"] = resp
|
||||||
if err != nil {
|
|
||||||
resResult["errno"] = "E10008"
|
|
||||||
resResult["errmsg"] = err.Error()
|
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
result["mappings"] = idxs
|
|
||||||
resResult["payload"] = result
|
|
||||||
|
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler APIHandler) HandleGetIndicesAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
|
||||||
indices, err := getESIndices(handler.Config.Elasticsearch)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
handler.WriteJSON(w, map[string]interface{}{
|
|
||||||
"errno": "0",
|
|
||||||
"errmsg": "",
|
|
||||||
"payload": indices,
|
|
||||||
}, http.StatusOK)
|
|
||||||
}
|
|
||||||
|
|
||||||
func getESIndices(esName string) ([]string, error) {
|
|
||||||
client := elastic.GetClient(esName)
|
|
||||||
esConfig := elastic.GetConfig(esName)
|
|
||||||
url := fmt.Sprintf("%s/_cat/indices?format=json", esConfig.Endpoint)
|
|
||||||
result, err := client.Request("GET", url, nil)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var catIndices = []struct {
|
|
||||||
Index string `json:"index"`
|
|
||||||
}{}
|
|
||||||
err = json.Unmarshal(result.Body, &catIndices)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
var indices = []string{}
|
|
||||||
for _, index := range catIndices {
|
|
||||||
if strings.HasPrefix(index.Index, ".") {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
indices = append(indices, index.Index)
|
|
||||||
}
|
|
||||||
|
|
||||||
return indices, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func formatESSearchResult(esResp *elastic.SearchResponse) map[string]interface{} {
|
func formatESSearchResult(esResp *elastic.SearchResponse) map[string]interface{} {
|
||||||
total := esResp.Hits.Total
|
total := esResp.Hits.Total
|
||||||
if len(esResp.Hits.Hits) == 0 {
|
if len(esResp.Hits.Hits) == 0 {
|
||||||
|
|
|
@ -28,76 +28,78 @@ func (handler APIHandler) GetDictListAction(w http.ResponseWriter, req *http.Req
|
||||||
from, _ = strconv.Atoi(fromStr)
|
from, _ = strconv.Atoi(fromStr)
|
||||||
size, _ = strconv.Atoi(sizeStr)
|
size, _ = strconv.Atoi(sizeStr)
|
||||||
tags = strings.Split(tag, ",")
|
tags = strings.Split(tag, ",")
|
||||||
|
resp = newResponseBody()
|
||||||
)
|
)
|
||||||
if len(tags) > 3 {
|
if len(tags) > 3 {
|
||||||
tags = tags[0:3]
|
tags = tags[0:3]
|
||||||
}
|
}
|
||||||
rel, err := model2.GetDictList(from, size, name, tags)
|
rel, err := model2.GetDictList(from, size, name, tags)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handler.Error(w, err)
|
resp["error"] = err
|
||||||
}
|
resp["status"] = false
|
||||||
resp := map[string]interface{}{
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
"errno": "0",
|
return
|
||||||
"errmsg": "",
|
|
||||||
"data": rel,
|
|
||||||
}
|
}
|
||||||
|
resp["payload"] = rel
|
||||||
handler.WriteJSON(w, resp, http.StatusOK)
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler APIHandler) CreateDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (handler APIHandler) CreateDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
//id := ps.ByName("id")
|
id := ps.ByName("id")
|
||||||
|
if strings.Trim(id, "/") == "" {
|
||||||
|
id = util.GetUUID()
|
||||||
|
}
|
||||||
createdAt := time.Now()
|
createdAt := time.Now()
|
||||||
|
|
||||||
|
resp := newResponseBody()
|
||||||
dict := model2.Dict{
|
dict := model2.Dict{
|
||||||
ID: util.GetUUID(),
|
ID: id,
|
||||||
CreatedAt: createdAt,
|
CreatedAt: createdAt,
|
||||||
UpdatedAt: createdAt,
|
UpdatedAt: createdAt,
|
||||||
}
|
}
|
||||||
err := handler.DecodeJSON(req, &dict)
|
err := handler.DecodeJSON(req, &dict)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handler.WriteJSON(w, map[string]interface{}{
|
resp["status"] = false
|
||||||
"payload": nil,
|
resp["error"] = err
|
||||||
"errno": "E100001",
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
"errmsg": err.Error(),
|
|
||||||
}, http.StatusOK)
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = orm.Save(dict)
|
err = orm.Save(dict)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
resp["status"] = false
|
||||||
|
resp["error"] = err
|
||||||
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
handler.WriteJSON(w, map[string]interface{}{
|
resp["payload"] = dict
|
||||||
"payload": dict,
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
"errno": "0",
|
|
||||||
"errmsg": "",
|
|
||||||
}, http.StatusOK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler APIHandler) DeleteDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (handler APIHandler) DeleteDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
id := ps.ByName("id")
|
id := ps.ByName("id")
|
||||||
dict := model2.Dict{}
|
dict := model2.Dict{}
|
||||||
dict.ID = id
|
dict.ID = id
|
||||||
|
resp := newResponseBody()
|
||||||
|
|
||||||
err := orm.Delete(dict)
|
err := orm.Delete(dict)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
resp["status"] = false
|
||||||
|
resp["error"] = err
|
||||||
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
handler.WriteJSON(w, map[string]interface{}{
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
"errno": "0",
|
|
||||||
"errmsg": "",
|
|
||||||
}, http.StatusOK)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler APIHandler) UpdateDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (handler APIHandler) UpdateDictItemAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
dict := model2.Dict{}
|
dict := model2.Dict{}
|
||||||
err := handler.DecodeJSON(req, &dict)
|
err := handler.DecodeJSON(req, &dict)
|
||||||
|
resp := newResponseBody()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
handler.WriteJSON(w, map[string]interface{}{
|
resp["status"] = false
|
||||||
"payload": nil,
|
resp["error"] = err
|
||||||
"errno": "E100002",
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
"errmsg": err.Error(),
|
|
||||||
}, http.StatusOK)
|
|
||||||
return
|
return
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -105,13 +107,13 @@ func (handler APIHandler) UpdateDictItemAction(w http.ResponseWriter, req *http.
|
||||||
|
|
||||||
err = orm.Update(dict)
|
err = orm.Update(dict)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
resp["status"] = false
|
||||||
|
resp["error"] = err
|
||||||
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
handler.WriteJSON(w, map[string]interface{}{
|
resp["payload"] = dict
|
||||||
"payload": dict,
|
handler.WriteJSON(w, resp, http.StatusOK)
|
||||||
"errno": "0",
|
|
||||||
"errmsg": "",
|
|
||||||
}, http.StatusOK)
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,7 @@ import (
|
||||||
func (handler APIHandler) HandleGetMappingsAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (handler APIHandler) HandleGetMappingsAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
client := elastic.GetClient(handler.Config.Elasticsearch)
|
client := elastic.GetClient(handler.Config.Elasticsearch)
|
||||||
indexName := ps.ByName("index")
|
indexName := ps.ByName("index")
|
||||||
resBody := map[string]interface{}{
|
resBody := newResponseBody()
|
||||||
"errno": "0",
|
|
||||||
"errmsg": "",
|
|
||||||
"payload": nil,
|
|
||||||
}
|
|
||||||
var copyAll = false
|
var copyAll = false
|
||||||
if indexName == "*" {
|
if indexName == "*" {
|
||||||
indexName = ""
|
indexName = ""
|
||||||
|
@ -23,8 +19,8 @@ func (handler APIHandler) HandleGetMappingsAction(w http.ResponseWriter, req *ht
|
||||||
}
|
}
|
||||||
_, _, idxs, err := client.GetMapping(copyAll, indexName)
|
_, _, idxs, err := client.GetMapping(copyAll, indexName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resBody["errno"] = "E30001"
|
resBody["error"] = err
|
||||||
resBody["errmsg"] = err.Error()
|
resBody["status"] = false
|
||||||
handler.WriteJSON(w, resBody, http.StatusOK)
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -40,3 +36,17 @@ func (handler APIHandler) HandleGetMappingsAction(w http.ResponseWriter, req *ht
|
||||||
|
|
||||||
handler.WriteJSON(w, resBody, http.StatusOK)
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (handler APIHandler) HandleGetIndicesAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
client := elastic.GetClient(handler.Config.Elasticsearch)
|
||||||
|
catIndices, err := client.GetIndices()
|
||||||
|
resBody := newResponseBody()
|
||||||
|
if err != nil {
|
||||||
|
resBody["status"] = false
|
||||||
|
resBody["error"] = err
|
||||||
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
resBody["payload"] = catIndices
|
||||||
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
httprouter "infini.sh/framework/core/api/router"
|
httprouter "infini.sh/framework/core/api/router"
|
||||||
|
@ -14,37 +15,35 @@ import (
|
||||||
|
|
||||||
func (handler APIHandler) ReindexAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (handler APIHandler) ReindexAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
reindexItem := &model.InfiniReindex{}
|
reindexItem := &model.InfiniReindex{}
|
||||||
resResult := map[string]interface{}{
|
id := ps.ByName("id")
|
||||||
"errno": "0",
|
if strings.Trim(id, "/") != "" {
|
||||||
"errmsg": "",
|
reindexItem.ID = id
|
||||||
"payload": nil,
|
|
||||||
}
|
}
|
||||||
|
resResult := newResponseBody()
|
||||||
|
|
||||||
err := handler.DecodeJSON(req, reindexItem)
|
err := handler.DecodeJSON(req, reindexItem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E20001"
|
resResult["error"] = err
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["status"] = false
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
//fmt.Println(reindexItem)
|
//fmt.Println(reindexItem)
|
||||||
|
|
||||||
taskID, err := reindex(handler.Config.Elasticsearch, reindexItem)
|
ID, err := reindex(handler.Config.Elasticsearch, reindexItem)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resResult["errno"] = "E20002"
|
resResult["error"] = err
|
||||||
resResult["errmsg"] = err.Error()
|
resResult["status"] = false
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resResult["payload"] = taskID
|
resResult["payload"] = ID
|
||||||
handler.WriteJSON(w, resResult, http.StatusOK)
|
handler.WriteJSON(w, resResult, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
func reindex(esName string, body *model.InfiniReindex) (string, error) {
|
func reindex(esName string, body *model.InfiniReindex) (string, error) {
|
||||||
client := elastic.GetClient(esName)
|
client := elastic.GetClient(esName)
|
||||||
esConfig := elastic.GetConfig(esName)
|
|
||||||
url := fmt.Sprintf("%s/_reindex?wait_for_completion=false", esConfig.Endpoint)
|
|
||||||
source := map[string]interface{}{
|
source := map[string]interface{}{
|
||||||
"index": body.Source.Index,
|
"index": body.Source.Index,
|
||||||
}
|
}
|
||||||
|
@ -66,19 +65,14 @@ func reindex(esName string, body *model.InfiniReindex) (string, error) {
|
||||||
}
|
}
|
||||||
buf, _ := json.Marshal(esBody)
|
buf, _ := json.Marshal(esBody)
|
||||||
//fmt.Println(string(buf))
|
//fmt.Println(string(buf))
|
||||||
reindexRes, err := client.Request("POST", url, buf)
|
reindexResp, err := client.Reindex(buf)
|
||||||
if err != nil {
|
|
||||||
return "", err
|
|
||||||
}
|
|
||||||
resBody := struct {
|
|
||||||
Task string `json:"task"`
|
|
||||||
}{}
|
|
||||||
err = json.Unmarshal(reindexRes.Body, &resBody)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
if body.ID == "" {
|
||||||
body.ID = util.GetUUID()
|
body.ID = util.GetUUID()
|
||||||
body.TaskId = resBody.Task
|
}
|
||||||
|
body.TaskId = reindexResp.Task
|
||||||
body.Status = model.ReindexStatusRunning
|
body.Status = model.ReindexStatusRunning
|
||||||
body.CreatedAt = time.Now()
|
body.CreatedAt = time.Now()
|
||||||
|
|
||||||
|
@ -91,28 +85,21 @@ func reindex(esName string, body *model.InfiniReindex) (string, error) {
|
||||||
|
|
||||||
func newResponseBody() map[string]interface{} {
|
func newResponseBody() map[string]interface{} {
|
||||||
return map[string]interface{}{
|
return map[string]interface{}{
|
||||||
"errno": "0",
|
"status": true,
|
||||||
"errmsg": "",
|
|
||||||
"payload": nil,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (handler APIHandler) HandleDeleteRebuildAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func (handler APIHandler) HandleDeleteRebuildAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
var ids = []string{}
|
id := ps.ByName("id")
|
||||||
|
var ids = []string{id}
|
||||||
resBody := newResponseBody()
|
resBody := newResponseBody()
|
||||||
err := handler.DecodeJSON(req, &ids)
|
err := deleteTasksByIds(handler.Config.Elasticsearch, ids)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resBody["errno"] = "E30001"
|
resBody["error"] = err
|
||||||
resBody["errmsg"] = err.Error()
|
resBody["status"] = false
|
||||||
handler.WriteJSON(w, resBody, http.StatusOK)
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = deleteTasksByTerms(handler.Config.Elasticsearch, ids)
|
|
||||||
if err != nil {
|
|
||||||
resBody["errno"] = "E30002"
|
|
||||||
resBody["errmsg"] = err.Error()
|
|
||||||
}
|
|
||||||
resBody["payload"] = true
|
resBody["payload"] = true
|
||||||
handler.WriteJSON(w, resBody, http.StatusOK)
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
@ -132,20 +119,20 @@ func (handler APIHandler) HandleGetRebuildListAction(w http.ResponseWriter, req
|
||||||
)
|
)
|
||||||
esResp, err := model.GetRebuildList(esName, from, size, name)
|
esResp, err := model.GetRebuildList(esName, from, size, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resBody["errno"] = "E20003"
|
resBody["error"] = err.Error()
|
||||||
resBody["errmsg"] = err.Error()
|
resBody["status"] = false
|
||||||
handler.WriteJSON(w, resBody, http.StatusOK)
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = SyncRebuildResult(esName)
|
err = SyncRebuildResult(esName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
resBody["errno"] = "E20004"
|
resBody["status"] = false
|
||||||
resBody["errmsg"] = err.Error()
|
resBody["error"] = err
|
||||||
handler.WriteJSON(w, resBody, http.StatusOK)
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
resBody["payload"] = formatESSearchResult(esResp)
|
resBody["payload"] = esResp
|
||||||
handler.WriteJSON(w, resBody, http.StatusOK)
|
handler.WriteJSON(w, resBody, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,11 +176,11 @@ func SyncRebuildResult(esName string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildTermsQuery(terms []string) string {
|
func buildTermsQuery(fieldName string, terms []string) string {
|
||||||
esBody := `{
|
esBody := `{
|
||||||
"query":{
|
"query":{
|
||||||
"terms": {
|
"terms": {
|
||||||
"_id": [
|
"%s": [
|
||||||
%s
|
%s
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -203,24 +190,14 @@ func buildTermsQuery(terms []string) string {
|
||||||
for _, term := range terms {
|
for _, term := range terms {
|
||||||
strTerms += fmt.Sprintf(`"%s",`, term)
|
strTerms += fmt.Sprintf(`"%s",`, term)
|
||||||
}
|
}
|
||||||
esBody = fmt.Sprintf(esBody, strTerms[0:len(strTerms)-1])
|
esBody = fmt.Sprintf(esBody, fieldName, strTerms[0:len(strTerms)-1])
|
||||||
return esBody
|
return esBody
|
||||||
}
|
}
|
||||||
|
|
||||||
func deleteTasksByTerms(esName string, terms []string) error {
|
func deleteTasksByIds(esName string, terms []string) error {
|
||||||
client := elastic.GetClient(esName)
|
client := elastic.GetClient(esName)
|
||||||
esConfig := elastic.GetConfig(esName)
|
esBody := buildTermsQuery("_id", terms)
|
||||||
url := fmt.Sprintf("%s/infinireindex/_delete_by_query", esConfig.Endpoint)
|
deleteRes, err := client.DeleteByQuery("infinireindex", []byte(esBody))
|
||||||
esBody := buildTermsQuery(terms)
|
|
||||||
result, err := client.Request("POST", url, []byte(esBody))
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
var deleteRes = struct {
|
|
||||||
Deleted int `json:"deleted"`
|
|
||||||
Total int `json:"total"`
|
|
||||||
}{}
|
|
||||||
err = json.Unmarshal(result.Body, &deleteRes)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
15
api/init.go
15
api/init.go
|
@ -17,21 +17,20 @@ func Init(cfg *config.AppConfig) {
|
||||||
var pathPrefix = "/_search-center/"
|
var pathPrefix = "/_search-center/"
|
||||||
//ui.HandleUIMethod(api.POST, "/api/get_indices",index_management.API1)
|
//ui.HandleUIMethod(api.POST, "/api/get_indices",index_management.API1)
|
||||||
ui.HandleUIMethod(api.GET, pathPrefix+"dict/_search", handler.GetDictListAction)
|
ui.HandleUIMethod(api.GET, pathPrefix+"dict/_search", handler.GetDictListAction)
|
||||||
ui.HandleUIMethod(api.POST, pathPrefix+"dict/_create", handler.CreateDictItemAction)
|
ui.HandleUIMethod(api.POST, pathPrefix+"dict/*id", handler.CreateDictItemAction)
|
||||||
//ui.HandleUIMethod(api.GET, "/api/dict/:id",handler.GetDictItemAction)
|
//ui.HandleUIMethod(api.GET, "/api/dict/:id",handler.GetDictItemAction)
|
||||||
ui.HandleUIMethod(api.DELETE, pathPrefix+"dict/:id", handler.DeleteDictItemAction)
|
ui.HandleUIMethod(api.DELETE, pathPrefix+"dict/:id", handler.DeleteDictItemAction)
|
||||||
//ui.HandleUIMethod(api.DELETE, "/api/dict/", handler.DeleteDictItemAction2)
|
ui.HandleUIMethod(api.PUT, pathPrefix+"dict/:id", handler.UpdateDictItemAction)
|
||||||
ui.HandleUIMethod(api.POST, pathPrefix+"dict/_update", handler.UpdateDictItemAction)
|
|
||||||
ui.HandleUIMethod(api.POST, pathPrefix+"doc/:index/_search", handler.HandleSearchDocumentAction)
|
ui.HandleUIMethod(api.POST, pathPrefix+"doc/:index/_search", handler.HandleSearchDocumentAction)
|
||||||
ui.HandleUIMethod(api.POST, pathPrefix+"doc/:index/_create", handler.HandleAddDocumentAction)
|
ui.HandleUIMethod(api.POST, pathPrefix+"doc/:index/_create", handler.HandleAddDocumentAction)
|
||||||
ui.HandleUIMethod(api.PUT, pathPrefix+"doc/:index/:id", handler.HandleUpdateDocumentAction)
|
ui.HandleUIMethod(api.PUT, pathPrefix+"doc/:index/:id", handler.HandleUpdateDocumentAction)
|
||||||
ui.HandleUIMethod(api.DELETE, pathPrefix+"doc/:index/:id", handler.HandleDeleteDocumentAction)
|
ui.HandleUIMethod(api.DELETE, pathPrefix+"doc/:index/:id", handler.HandleDeleteDocumentAction)
|
||||||
ui.HandleUIMethod(api.GET, pathPrefix+"indices/_cat", handler.HandleGetIndicesAction)
|
|
||||||
|
|
||||||
ui.HandleUIMethod(api.POST, pathPrefix+"rebuild/_create", handler.ReindexAction)
|
ui.HandleUIMethod(api.POST, pathPrefix+"rebuild/*id", handler.ReindexAction)
|
||||||
ui.HandleUIMethod(api.GET, pathPrefix+"rebuild/list", handler.HandleGetRebuildListAction)
|
ui.HandleUIMethod(api.GET, pathPrefix+"rebuild/_search", handler.HandleGetRebuildListAction)
|
||||||
ui.HandleUIMethod(api.POST, pathPrefix+"rebuild/_delete", handler.HandleDeleteRebuildAction)
|
ui.HandleUIMethod(api.DELETE, pathPrefix+"rebuild/:id", handler.HandleDeleteRebuildAction)
|
||||||
ui.HandleUIMethod(api.GET, pathPrefix+"indices/_mappings/:index", handler.HandleGetMappingsAction)
|
ui.HandleUIMethod(api.GET, pathPrefix+"_cat/indices", handler.HandleGetIndicesAction)
|
||||||
|
ui.HandleUIMethod(api.GET, pathPrefix+"index/:index/_mappings", handler.HandleGetMappingsAction)
|
||||||
|
|
||||||
task.RegisterScheduleTask(task.ScheduleTask{
|
task.RegisterScheduleTask(task.ScheduleTask{
|
||||||
Description: "sync reindex task result to index infinireindex",
|
Description: "sync reindex task result to index infinireindex",
|
||||||
|
|
|
@ -45875,10 +45875,10 @@ const mappings = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
'get /_search-center/indices/_cat': function(req, res){
|
// 'get /_search-center/indices/_cat': function(req, res){
|
||||||
res.send(data)
|
// res.send(data)
|
||||||
},
|
// },
|
||||||
'get /_search-center/indices/_mappings/:index': function(req, res){
|
// 'get /_search-center/indices/_mappings/:index': function(req, res){
|
||||||
res.send(mappings)
|
// res.send(mappings)
|
||||||
}
|
// }
|
||||||
}
|
}
|
|
@ -426,7 +426,7 @@ let data = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
'get /_search-center/rebuild/list': function(req, res){
|
// 'get /_search-center/rebuild/list': function(req, res){
|
||||||
res.send(data)
|
// res.send(data)
|
||||||
}
|
// }
|
||||||
}
|
}
|
|
@ -8,6 +8,7 @@ import Editor, {monaco} from '@monaco-editor/react';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import {createDependencyProposals} from './autocomplete';
|
import {createDependencyProposals} from './autocomplete';
|
||||||
import InputSelect from '@/components/infini/InputSelect';
|
import InputSelect from '@/components/infini/InputSelect';
|
||||||
|
import {getFields} from '@/utils/elasticsearch';
|
||||||
|
|
||||||
function findParentIdentifier(textUntilPosition){
|
function findParentIdentifier(textUntilPosition){
|
||||||
let chars = textUntilPosition;
|
let chars = textUntilPosition;
|
||||||
|
@ -202,6 +203,9 @@ class EditableCell extends React.Component {
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
const {properties} = doclist.mappings[record._index].mappings;
|
const {properties} = doclist.mappings[record._index].mappings;
|
||||||
|
if(!properties[key]){
|
||||||
|
return '';
|
||||||
|
}
|
||||||
return properties[key].type;
|
return properties[key].type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -296,14 +300,7 @@ class EditableCell extends React.Component {
|
||||||
let keys = [];
|
let keys = [];
|
||||||
let sortObj = {};
|
let sortObj = {};
|
||||||
if(doclist.mappings){
|
if(doclist.mappings){
|
||||||
for(let mkey in doclist.mappings){
|
keys = getFields(doclist.index, doclist.mappings)
|
||||||
Object.keys(doclist.mappings[mkey].mappings.properties).forEach(key=>{
|
|
||||||
if(!keys.includes(key)){
|
|
||||||
keys.push(key);
|
|
||||||
sortObj[key] = this.isSortable(doclist.mappings[mkey].mappings.properties[key].type);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
for(let key of keys){
|
for(let key of keys){
|
||||||
if(["_index"].includes(key)){
|
if(["_index"].includes(key)){
|
||||||
|
@ -344,7 +341,7 @@ class EditableCell extends React.Component {
|
||||||
<Table
|
<Table
|
||||||
components={components}
|
components={components}
|
||||||
bordered
|
bordered
|
||||||
rowKey="id"
|
rowKey={record=>(record._index+record.id)}
|
||||||
onChange={this.handleTableChange}
|
onChange={this.handleTableChange}
|
||||||
size="small"
|
size="small"
|
||||||
loading={doclist.isLoading}
|
loading={doclist.isLoading}
|
||||||
|
@ -398,6 +395,12 @@ class Doucment extends React.Component {
|
||||||
if(!cluster){
|
if(!cluster){
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
dispatch({
|
||||||
|
type: 'document/fetchMappings',
|
||||||
|
payload: {
|
||||||
|
cluster,
|
||||||
|
}
|
||||||
|
});
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'document/fetchIndices',
|
type: 'document/fetchIndices',
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -510,10 +513,10 @@ class Doucment extends React.Component {
|
||||||
//console.log(this.props.document);
|
//console.log(this.props.document);
|
||||||
let clusterIndices = this.props.document.clusterIndices || [];
|
let clusterIndices = this.props.document.clusterIndices || [];
|
||||||
|
|
||||||
clusterIndices = clusterIndices.map((index) =>{
|
clusterIndices = clusterIndices.filter(index => !index.index.startsWith('.')).map((index) =>{
|
||||||
return {
|
return {
|
||||||
label: index,
|
label: index.index,
|
||||||
value: index,
|
value: index.index,
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
const clusters = ["single-es"];
|
const clusters = ["single-es"];
|
||||||
|
|
|
@ -3,14 +3,14 @@ import { connect } from 'dva';
|
||||||
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
|
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
|
||||||
import {Steps, Card, Form, Select, Input,Button, Divider,message, InputNumber} from 'antd';
|
import {Steps, Card, Form, Select, Input,Button, Divider,message, InputNumber} from 'antd';
|
||||||
import InputSelect from '@/components/infini/InputSelect';
|
import InputSelect from '@/components/infini/InputSelect';
|
||||||
|
import {getFields} from '@/utils/elasticsearch';
|
||||||
|
|
||||||
const {Step} = Steps;
|
const {Step} = Steps;
|
||||||
const {Option} = Select;
|
const {Option} = Select;
|
||||||
const {TextArea} = Input;
|
const {TextArea} = Input;
|
||||||
|
|
||||||
@Form.create()
|
@Form.create()
|
||||||
@connect(({document,rebuild}) => ({
|
@connect(({rebuild}) => ({
|
||||||
document,
|
|
||||||
rebuild,
|
rebuild,
|
||||||
}))
|
}))
|
||||||
class Rebuild extends Component {
|
class Rebuild extends Component {
|
||||||
|
@ -19,12 +19,6 @@ class Rebuild extends Component {
|
||||||
}
|
}
|
||||||
componentDidMount(){
|
componentDidMount(){
|
||||||
const {dispatch} = this.props;
|
const {dispatch} = this.props;
|
||||||
dispatch({
|
|
||||||
type:'document/fetchIndices',
|
|
||||||
payload:{
|
|
||||||
cluster: 'sinlge-es'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'rebuild/fetchMappings',
|
type: 'rebuild/fetchMappings',
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -37,29 +31,7 @@ class Rebuild extends Component {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
let {mappings} = this.props.rebuild;
|
let {mappings} = this.props.rebuild;
|
||||||
let filterMappings = {};
|
return getFields(index, mappings);
|
||||||
if(index.indexOf("*")>0){
|
|
||||||
index = index.replace("*", '');
|
|
||||||
for(let key in mappings){
|
|
||||||
if(key.startsWith(index)){
|
|
||||||
filterMappings['key'] = mappings[key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
if(!mappings[index]){
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
filterMappings[index] = mappings[index];
|
|
||||||
}
|
|
||||||
|
|
||||||
let fields = [];
|
|
||||||
for(let key in filterMappings){
|
|
||||||
for(let fi in filterMappings[key].mappings.properties){
|
|
||||||
fields.push(fi);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return fields;
|
|
||||||
}
|
}
|
||||||
handleSourceIndexChange = (v) =>{
|
handleSourceIndexChange = (v) =>{
|
||||||
const {dispatch, form} = this.props;
|
const {dispatch, form} = this.props;
|
||||||
|
@ -74,12 +46,12 @@ class Rebuild extends Component {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
renderSteps = (currentStep) => {
|
renderSteps = (currentStep) => {
|
||||||
let {clusterIndices} = this.props.document;
|
let {mappings} = this.props.rebuild;
|
||||||
clusterIndices = clusterIndices || [];
|
mappings = mappings || {};
|
||||||
let indices = clusterIndices.map((item)=>{
|
let indices = Object.keys(mappings).map((key)=>{
|
||||||
return {
|
return {
|
||||||
label: item,
|
label: key,
|
||||||
value: item,
|
value: key,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
var stepDom = '';
|
var stepDom = '';
|
||||||
|
|
|
@ -79,7 +79,9 @@ class RebuildList extends React.Component {
|
||||||
const {dispatch} = this.props;
|
const {dispatch} = this.props;
|
||||||
dispatch({
|
dispatch({
|
||||||
type: 'rebuildlist/deleteTask',
|
type: 'rebuildlist/deleteTask',
|
||||||
payload: [record.id],
|
payload: {
|
||||||
|
id: record.id,
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import {getDocList, saveDoc, deleteDoc, addDoc, getIndices} from '@/services/doc';
|
import {getDocList, saveDoc, deleteDoc, addDoc} from '@/services/doc';
|
||||||
|
import {getMappings, getIndices} from '@/services/indices';
|
||||||
|
import {formatESSearchResult} from '@/utils/utils';
|
||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
|
|
||||||
function encodeObjectField(doc){
|
function encodeObjectField(doc){
|
||||||
|
@ -44,7 +46,7 @@ export default {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let res = yield call(getDocList, payload);
|
let res = yield call(getDocList, payload);
|
||||||
if(res.errno != "0"){
|
if(res.status === false){
|
||||||
message.warn("加载数据失败")
|
message.warn("加载数据失败")
|
||||||
yield put({
|
yield put({
|
||||||
type: 'saveData',
|
type: 'saveData',
|
||||||
|
@ -54,7 +56,8 @@ export default {
|
||||||
})
|
})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let indices = Object.keys(res.payload.mappings); //indices state can remove
|
res.payload = formatESSearchResult(res.payload);
|
||||||
|
let indices = []; //indices state can remove
|
||||||
if(res.payload.data && res.payload.data.length > 0){
|
if(res.payload.data && res.payload.data.length > 0){
|
||||||
for(let doc of res.payload.data){
|
for(let doc of res.payload.data){
|
||||||
if(!indices.includes(doc._index)){
|
if(!indices.includes(doc._index)){
|
||||||
|
@ -90,7 +93,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let res = yield call(saveDoc, payload);
|
let res = yield call(saveDoc, payload);
|
||||||
if(res.errno != "0"){
|
if(res.status === false){
|
||||||
message.warn("保存数据失败")
|
message.warn("保存数据失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -118,7 +121,7 @@ export default {
|
||||||
if(typeof res == 'string'){
|
if(typeof res == 'string'){
|
||||||
res = JSON.parse(res);
|
res = JSON.parse(res);
|
||||||
}
|
}
|
||||||
if(res.errno != "0"){
|
if(res.status === false){
|
||||||
message.warn("删除数据失败")
|
message.warn("删除数据失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -143,7 +146,7 @@ export default {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let res = yield call(addDoc, payload);
|
let res = yield call(addDoc, payload);
|
||||||
if(res.errno != "0"){
|
if(res.status === false){
|
||||||
message.warn("添加文档失败")
|
message.warn("添加文档失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -162,7 +165,7 @@ export default {
|
||||||
},
|
},
|
||||||
*fetchIndices({payload}, {call, put}){
|
*fetchIndices({payload}, {call, put}){
|
||||||
let resp = yield call(getIndices)
|
let resp = yield call(getIndices)
|
||||||
if(resp.errno != "0"){
|
if(resp.status === false){
|
||||||
message.warn("获取数据失败")
|
message.warn("获取数据失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -173,6 +176,19 @@ export default {
|
||||||
cluster: payload.cluster,
|
cluster: payload.cluster,
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
*fetchMappings({payload}, {call, put}){
|
||||||
|
let resp = yield call(getMappings, payload);
|
||||||
|
if(resp.status === false){
|
||||||
|
message.warn("get mappings failed")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
yield put({
|
||||||
|
type: 'saveData',
|
||||||
|
payload: {
|
||||||
|
mappings: resp.payload,
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
reducers: {
|
reducers: {
|
||||||
|
|
|
@ -15,7 +15,7 @@ export default {
|
||||||
effects:{
|
effects:{
|
||||||
*addTask({payload}, {call, put}){
|
*addTask({payload}, {call, put}){
|
||||||
let resp = yield call(reindex, payload);
|
let resp = yield call(reindex, payload);
|
||||||
if(resp.errno != "0"){
|
if(!resp.status){
|
||||||
message.warn("rebuild failed")
|
message.warn("rebuild failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@ export default {
|
||||||
},
|
},
|
||||||
*fetchMappings({payload}, {call, put}){
|
*fetchMappings({payload}, {call, put}){
|
||||||
let resp = yield call(getMappings, payload);
|
let resp = yield call(getMappings, payload);
|
||||||
if(resp.errno != "0"){
|
if(resp.status === false){
|
||||||
message.warn("get mappings failed")
|
message.warn("get mappings failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import {getRebuildList,reindex, deleteRebuild} from '@/services/rebuild';
|
import {getRebuildList,reindex, deleteRebuild} from '@/services/rebuild';
|
||||||
import { message } from 'antd';
|
import { message } from 'antd';
|
||||||
|
import {formatESSearchResult} from '@/utils/utils';
|
||||||
|
|
||||||
|
|
||||||
const delay = (ms) => new Promise((resolve) => {
|
const delay = (ms) => new Promise((resolve) => {
|
||||||
setTimeout(resolve, ms);
|
setTimeout(resolve, ms);
|
||||||
|
@ -25,10 +27,11 @@ export default {
|
||||||
from: (payload.pageIndex - 1) * payload.pageSize,
|
from: (payload.pageIndex - 1) * payload.pageSize,
|
||||||
size: payload.pageSize,
|
size: payload.pageSize,
|
||||||
})
|
})
|
||||||
if(resp.errno != "0"){
|
if(!resp.status){
|
||||||
message.error('fetch data failed')
|
message.error('fetch data failed')
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
resp.payload = formatESSearchResult(resp.payload)
|
||||||
yield put({
|
yield put({
|
||||||
type: 'saveData',
|
type: 'saveData',
|
||||||
payload: {
|
payload: {
|
||||||
|
@ -84,12 +87,12 @@ export default {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
let resp = yield call(deleteRebuild, payload);
|
let resp = yield call(deleteRebuild, payload);
|
||||||
if(resp.errno != "0"){
|
if(resp.status === false){
|
||||||
message.error("delete failed")
|
message.error("delete failed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
let {data, total} = yield select(state=>state.rebuildlist);
|
let {data, total} = yield select(state=>state.rebuildlist);
|
||||||
let newData = data.filter(item=> !payload.includes(item.id));
|
let newData = data.filter(item=> payload.id != item.id);
|
||||||
yield put({
|
yield put({
|
||||||
type: 'saveData',
|
type: 'saveData',
|
||||||
payload: {
|
payload: {
|
||||||
|
|
|
@ -63,10 +63,11 @@ export default {
|
||||||
effects: {
|
effects: {
|
||||||
*fetchDictList({payload}, {call, put}){
|
*fetchDictList({payload}, {call, put}){
|
||||||
const resp = yield call(getDictList, payload);
|
const resp = yield call(getDictList, payload);
|
||||||
if(resp.errno != "0" || !resp.data.Result){
|
if(resp.status ===false){
|
||||||
|
message.error(resp.error)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
resp.data.Result = resp.data.Result.map((item)=>{
|
resp.payload.Result = resp.payload.Result.map((item)=>{
|
||||||
item.content = utf8.decode(atob(item.content))
|
item.content = utf8.decode(atob(item.content))
|
||||||
return item;
|
return item;
|
||||||
})
|
})
|
||||||
|
@ -77,8 +78,8 @@ export default {
|
||||||
yield put({
|
yield put({
|
||||||
type: 'saveData',
|
type: 'saveData',
|
||||||
payload: {
|
payload: {
|
||||||
dictList: resp.data.Result,
|
dictList: resp.payload.Result,
|
||||||
total: resp.data.Total,
|
total: resp.payload.Total,
|
||||||
search: search,
|
search: search,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
@ -90,7 +91,7 @@ export default {
|
||||||
}
|
}
|
||||||
upVals.content = btoa(utf8.encode(upVals.content));
|
upVals.content = btoa(utf8.encode(upVals.content));
|
||||||
const rel = yield call(addDict, upVals);
|
const rel = yield call(addDict, upVals);
|
||||||
if(rel.errno != "0"){
|
if(rel.status === false){
|
||||||
message.warn('添加失败:'+ rel.errmsg)
|
message.warn('添加失败:'+ rel.errmsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -110,7 +111,7 @@ export default {
|
||||||
let rawContent = payload.content;
|
let rawContent = payload.content;
|
||||||
payload.content = btoa(utf8.encode(payload.content));
|
payload.content = btoa(utf8.encode(payload.content));
|
||||||
const rel = yield call(updateDict, payload);
|
const rel = yield call(updateDict, payload);
|
||||||
if(rel.errno != "0"){
|
if(rel.status === false){
|
||||||
message.warn('修改:'+ rel.errmsg)
|
message.warn('修改:'+ rel.errmsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -131,7 +132,7 @@ export default {
|
||||||
if(typeof rel !== 'object'){
|
if(typeof rel !== 'object'){
|
||||||
rel = JSON.parse(rel);
|
rel = JSON.parse(rel);
|
||||||
}
|
}
|
||||||
if(rel.errno != "0"){
|
if(rel.status === false){
|
||||||
message.warn('删除失败:'+ rel.errmsg)
|
message.warn('删除失败:'+ rel.errmsg)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,15 +25,10 @@ export async function deleteDoc(params) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addDoc(params) {
|
export async function addDoc(params) {
|
||||||
|
let id = params.data.id || '';
|
||||||
delete(params.data, 'id');
|
delete(params.data, 'id');
|
||||||
return request(`${pathPrefix}/doc/${params.index}/_create`, {
|
return request(`${pathPrefix}/doc/${params.index}/${id}`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: params.data,
|
body: params.data,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getIndices(params) {
|
|
||||||
return request(`${pathPrefix}/indices/_cat`, {
|
|
||||||
method: 'GET'
|
|
||||||
});
|
|
||||||
}
|
|
|
@ -3,9 +3,16 @@ import {pathPrefix} from './common';
|
||||||
|
|
||||||
export async function getMappings(payload){
|
export async function getMappings(payload){
|
||||||
let index = payload.index || '*'
|
let index = payload.index || '*'
|
||||||
let url = `${pathPrefix}/indices/_mappings/${index}`;
|
let url = `${pathPrefix}/index/${index}/_mappings`;
|
||||||
return request(url,{
|
return request(url,{
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
expirys: 0,
|
expirys: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function getIndices(params) {
|
||||||
|
return request(`${pathPrefix}/_cat/indices`, {
|
||||||
|
method: 'GET'
|
||||||
|
});
|
||||||
|
}
|
|
@ -2,7 +2,8 @@ import request from '@/utils/request';
|
||||||
import {pathPrefix} from './common';
|
import {pathPrefix} from './common';
|
||||||
|
|
||||||
export async function reindex(payload){
|
export async function reindex(payload){
|
||||||
let url = `${pathPrefix}/rebuild/_create`;
|
let id = payload.id || '';
|
||||||
|
let url = `${pathPrefix}/rebuild/${id}`;
|
||||||
return request(url,{
|
return request(url,{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: payload,
|
body: payload,
|
||||||
|
@ -11,17 +12,17 @@ export async function reindex(payload){
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function deleteRebuild(payload){
|
export async function deleteRebuild(payload){
|
||||||
let url = `${pathPrefix}/rebuild/_delete`;
|
let id = payload.id;
|
||||||
|
let url = `${pathPrefix}/rebuild/${id}`;
|
||||||
return request(url,{
|
return request(url,{
|
||||||
method: 'POST',
|
method: 'DELETE',
|
||||||
body: payload,
|
|
||||||
expirys: 0,
|
expirys: 0,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export async function getRebuildList(payload){
|
export async function getRebuildList(payload){
|
||||||
let url = `${pathPrefix}/rebuild/list?`;
|
let url = `${pathPrefix}/rebuild/_search?`;
|
||||||
payload.from && (url+=`from=${payload.from}`)
|
payload.from && (url+=`from=${payload.from}`)
|
||||||
payload.size && (url+=`&size=${payload.size}`)
|
payload.size && (url+=`&size=${payload.size}`)
|
||||||
payload.name && (url+=`&name=${payload.name}`)
|
payload.name && (url+=`&name=${payload.name}`)
|
||||||
|
|
|
@ -13,7 +13,8 @@ export async function getDictList(payload){
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addDict(payload){
|
export async function addDict(payload){
|
||||||
return request(`${pathPrefix}/dict/_create`,{
|
let id = payload.id || '';
|
||||||
|
return request(`${pathPrefix}/dict/${id}`,{
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: payload,
|
body: payload,
|
||||||
expirys: 0,
|
expirys: 0,
|
||||||
|
@ -28,8 +29,9 @@ export async function deleteDict(payload){
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function updateDict(payload){
|
export async function updateDict(payload){
|
||||||
return request(`${pathPrefix}/dict/_update`,{
|
let id = payload.id || '';
|
||||||
method: 'POST',
|
return request(`${pathPrefix}/dict/${id}`,{
|
||||||
|
method: 'PUT',
|
||||||
body: payload,
|
body: payload,
|
||||||
expirys: 0,
|
expirys: 0,
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
export function getFields(index, mappings){
|
||||||
|
if(!index){
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
let filterMappings = {};
|
||||||
|
if(index.indexOf("*")>0){
|
||||||
|
index = index.replace("*", '');
|
||||||
|
for(let key in mappings){
|
||||||
|
if(key.startsWith(index)){
|
||||||
|
filterMappings['key'] = mappings[key];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
if(!mappings[index]){
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
filterMappings[index] = mappings[index];
|
||||||
|
}
|
||||||
|
|
||||||
|
let fields = [];
|
||||||
|
for(let key in filterMappings){
|
||||||
|
for(let fi in filterMappings[key].mappings.properties){
|
||||||
|
fields.push(fi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return fields;
|
||||||
|
}
|
|
@ -181,3 +181,25 @@ export function formatWan(val) {
|
||||||
export function isAntdPro() {
|
export function isAntdPro() {
|
||||||
return window.location.hostname === 'preview.pro.ant.design';
|
return window.location.hostname === 'preview.pro.ant.design';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatESSearchResult(esResp) {
|
||||||
|
const total = esResp.hits.total
|
||||||
|
if(esResp.hits.hits.length == 0){
|
||||||
|
return {
|
||||||
|
total: total,
|
||||||
|
data: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
let dataArr = [];
|
||||||
|
for(let hit of esResp.hits.hits) {
|
||||||
|
if(!hit._source.id){
|
||||||
|
hit._source["id"] = hit._id
|
||||||
|
}
|
||||||
|
hit._source["_index"] = hit._index
|
||||||
|
dataArr.push(hit._source)
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
total: total,
|
||||||
|
data: dataArr,
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue