modify mock

This commit is contained in:
silenceqi 2021-01-08 23:23:18 +08:00
parent e58c2412af
commit 7f8c3051e2
10 changed files with 934 additions and 636 deletions

View File

@ -13,8 +13,8 @@ import (
"infini.sh/search-center/model"
)
func (handler APIHandler) ReindexAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
reindexItem := &model.InfiniReindex{}
func (handler APIHandler) HandleReindexAction(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
reindexItem := &model.Reindex{}
id := ps.ByName("id")
if strings.Trim(id, "/") != "" {
reindexItem.ID = id
@ -42,7 +42,7 @@ func (handler APIHandler) ReindexAction(w http.ResponseWriter, req *http.Request
handler.WriteJSON(w, resResult, http.StatusOK)
}
func reindex(esName string, body *model.InfiniReindex) (string, error) {
func reindex(esName string, body *model.Reindex) (string, error) {
client := elastic.GetClient(esName)
source := map[string]interface{}{
"index": body.Source.Index,
@ -138,7 +138,7 @@ func (handler APIHandler) HandleGetRebuildListAction(w http.ResponseWriter, req
func SyncRebuildResult(esName string) error {
client := elastic.GetClient(esName)
esBody := `{"query":{"match":{"status": "RUNNING"}}}`
esBody := fmt.Sprintf(`{"query":{"match":{"status": "%s"}}}`, model.ReindexStatusRunning)
esRes, err := client.SearchWithRawQueryDSL("infinireindex", []byte(esBody))
if err != nil {
return err

View File

@ -26,7 +26,7 @@ func Init(cfg *config.AppConfig) {
ui.HandleUIMethod(api.PUT, pathPrefix+"doc/:index/:id", handler.HandleUpdateDocumentAction)
ui.HandleUIMethod(api.DELETE, pathPrefix+"doc/:index/:id", handler.HandleDeleteDocumentAction)
ui.HandleUIMethod(api.POST, pathPrefix+"rebuild/*id", handler.ReindexAction)
ui.HandleUIMethod(api.POST, pathPrefix+"rebuild/*id", handler.HandleReindexAction)
ui.HandleUIMethod(api.GET, pathPrefix+"rebuild/_search", handler.HandleGetRebuildListAction)
ui.HandleUIMethod(api.DELETE, pathPrefix+"rebuild/:id", handler.HandleDeleteRebuildAction)
ui.HandleUIMethod(api.GET, pathPrefix+"_cat/indices", handler.HandleGetIndicesAction)

View File

@ -70,7 +70,7 @@ func main() {
}, func() {
orm.RegisterSchema(model.Dict{})
orm.RegisterSchema(model.InfiniReindex{})
orm.RegisterSchema(model.Reindex{})
})
}

View File

@ -1,6 +0,0 @@
package model
type PageResult struct {
Total int `json:"total"`
Data interface{} `json:"data"`
}

View File

@ -16,7 +16,9 @@ const (
ReindexStatusFailed ReindexStatus = "FAILED"
)
type InfiniReindex struct {
//const IndexReindex = ".reindex"
type Reindex struct {
ID string `json:"id" elastic_meta:"_id"`
Name string `json:"name" elastic_mapping:"name:{type:text}"`
Desc string `json:"desc" elastic_mapping:"desc:{type:text}"`

View File

@ -1,55 +1,81 @@
export const queryData = {
"errmsg": "",
"errno": "0",
"payload": {
"data": [
"took": 0,
"timed_out": false,
"hits": {
"total": {
"relation": "eq",
"value": 11
},
"max_score": 1,
"hits": [
{
"_index": "infini-test",
"_type": "_doc",
"_id": "jc6_jXYBKoaaPbVfj_8W",
"_source": {
"address": "hunan changsha",
"created_at": "2020-12-23T03:57:57.620Z",
"email": "liugq@qq.com",
"hobbies": "[\"basketball\",\"pingpan\"]",
"id": "jc6_jXYBKoaaPbVfj_8W",
"name": "liugq国家"
}
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "bvhm18dath2d6oa9046g",
"_source": {
"address": "hunan changsha",
"created_at": "2020-12-23T03:57:57.620Z",
"email": "786027438@qq.com",
"hobbies": "[\"test5\"]",
"id": "bvhm18dath2d6oa9046g",
"name": "hello4"
}
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "bvhlv6dath2d6oa9045g",
"_source": {
"address": "hunan changsha",
"created_at": "2020-12-23T03:57:57.620Z",
"email": "786027438@qq.com",
"hobbies": "[\"test2\"]",
"id": "bvhlv6dath2d6oa9045g",
"name": "test 词典"
}
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "bvhltpdath2d6oa90450",
"_source": {
"address": "hunan changsha",
"created_at": "2020-12-23T03:57:57.620Z",
"email": "786027438@qq.com",
"hobbies": "[\"test1\"]",
"id": "bvhltpdath2d6oa90450",
"name": "liugqy"
}
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "js7EjXYBKoaaPbVfvf-c",
"_source": {
"address": "hunan zhuzhou",
"created_at": "2020-12-23T03:59:57.620Z",
"email": "cincky@qq.com",
"hobbies": "[\"basketball\",\"badminton1\"]",
"id": "js7EjXYBKoaaPbVfvf-c",
"name": "cincky"
}
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "bvi5ellath2e0ukbq5e0",
"_source": {
"address": "湖北武汉2",
"created_at": "2020-12-23T03:57:57.620Z",
"email": "786027438@qq.com",
@ -58,32 +84,27 @@ export const queryData = {
],
"id": "bvi5ellath2e0ukbq5e0",
"name": "武汉test"
}
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "bvia41lath2eneoeeij0",
"_source": {
"address": "hunan changsha",
"created_at": "2020-12-23T03:57:57.620Z",
"email": "786027438@qq.com",
"hobbies": [
"test3"
],
"id": "bvia41lath2eneoeeij0",
"name": "铁路测试词典"
}
},
{
"_index": "infini-test",
"address": "beijing",
"created_at": "2020-12-23T03:57:57.620Z",
"email": "786027438@qq.com",
"hobbies": [
"basketball1",
"badminton"
],
"id": "bvia4ctath2eneoeeijg",
"name": "北京"
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "bvi5omtath2e0ukbq5eg",
"_source": {
"address": "湖北武汉",
"created_at": "2020-12-23T03:57:57.620Z",
"email": "786027438@qq.com",
@ -92,10 +113,30 @@ export const queryData = {
],
"id": "bvi5omtath2e0ukbq5eg",
"name": "武汉2"
}
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "bvhlsptath2d6oa9044g",
"_source": {
"address": "hunan changsha",
"created_at": "2020-12-29T08:24:49.715Z",
"email": "786027438@qq.com",
"hobbies": [
"test"
],
"id": "bvhlsptath2d6oa9044g",
"name": "hello"
}
},
{
"_index": "infini-test",
"_type": "_doc",
"_id": "bvhm0d5ath2d6oa90460",
"_source": {
"address": "hunan changsha1",
"age": 30,
"created_at": "2020-12-23T03:57:57.620Z",
"email": "786027438@qq.com",
"hobbies": [
@ -104,57 +145,9 @@ export const queryData = {
"id": "bvhm0d5ath2d6oa90460",
"name": "hello2"
}
],
"mappings": {
"infini-test": {
"mappings": {
"dynamic_templates": [
{
"strings": {
"mapping": {
"ignore_above": 256,
"type": "keyword"
},
"match_mapping_type": "string"
}
}
],
"properties": {
"address": {
"fields": {
"keyword": {
"ignore_above": 256,
"type": "keyword"
]
}
},
"type": "text"
},
"age": {
"type": "integer"
},
"created_at": {
"type": "date"
},
"email": {
"type": "keyword"
},
"hobbies": {
"type": "text"
},
"id": {
"ignore_above": 256,
"type": "keyword"
},
"name": {
"type": "text"
}
}
}
}
},
"total": {
"relation": "eq",
"value": 11
}
}
}
"status": true
};

View File

@ -12,37 +12,29 @@ function getUUID(len){
}
export default {
// 'post /_search-center/doc/:index': function(req, res){
// switch(req.body.action){
// case 'SAVE':
// res.send({
// errno: "0",
// errmsg: ""
// });
// break;
// case 'ADD':
// res.send({
// errno: "0",
// errmsg: "",
// payload: {
// ...req.body.payload,
// id: getUUID(),
// }
// });
// break;
// case 'DELETE':
// res.send({
// errno: "0"
// });
// break;
// default:
// res.send(queryData)
// }
// },
// 'get /_search-center/indices/_cat': function(req, res){
// res.send({
// errno: "0",
// payload: ["infini-test"],
// });
// }
'get /_search-center/doc/:index/_search': function(req, res){
res.send(queryData)
},
'post /_search-center/doc/:index/_create': function(req, res){
res.send({
status: true,
payload: {
...req.body.payload,
id: getUUID(),
}
});
},
'put /_search-center/doc/:index/:id': function(req, res){
res.send({
status: true,
payload: req.body
});
},
'delete /_search-center/doc/:index/:id': function(req, res){
res.send({
status: true,
payload: null,
});
}
}

View File

@ -1,20 +1,238 @@
let data = {
"errmsg": "",
"errno": "0",
"payload": [
"blogs",
"mock_log1",
"metricbeat-7.10.0-2020.12.24-000002",
"metricbeat-7.10.0-2020.11.24-000001",
"infinireindex",
"gateway_requests",
"infini-test1",
"dict",
"infini-test",
"mock_log",
"infini-test8",
"infini-dict"
]
{
"health": "green",
"index": "blogs",
"uuid": "3YOmOx_BSDqF-6EqAzBLVg",
"pri": "1",
"rep": "1",
"docs.count": "3",
"docs.deleted": "0",
"store.size": "29.2kb",
"pri.store.size": "14.6kb"
},
{
"health": "green",
"index": ".apm-agent-configuration",
"uuid": "uQiIf-y9TuaOaO1H0stK0g",
"pri": "1",
"rep": "1",
"docs.count": "0",
"docs.deleted": "0",
"store.size": "416b",
"pri.store.size": "208b"
},
{
"health": "green",
"index": ".kibana_2",
"uuid": "YI3glc42SOugYrw07g4ANw",
"pri": "1",
"rep": "1",
"docs.count": "0",
"docs.deleted": "0",
"store.size": "416b",
"pri.store.size": "208b"
},
{
"health": "green",
"index": ".kibana_1",
"uuid": "EK13_lDIRN-vSTd0WRFPgg",
"pri": "1",
"rep": "1",
"docs.count": "158",
"docs.deleted": "38",
"store.size": "20.9mb",
"pri.store.size": "10.4mb"
},
{
"health": "green",
"index": ".tasks",
"uuid": "F2IVDbwASJOGgSbhvs6rpQ",
"pri": "1",
"rep": "1",
"docs.count": "48",
"docs.deleted": "0",
"store.size": "148.2kb",
"pri.store.size": "74.1kb"
},
{
"health": "green",
"index": "mock_log1",
"uuid": "FEuAjVAYTCG5FJSVqjB4cA",
"pri": "1",
"rep": "1",
"docs.count": "45806",
"docs.deleted": "0",
"store.size": "4.1mb",
"pri.store.size": "2mb"
},
{
"health": "green",
"index": "metricbeat-7.10.0-2020.12.24-000002",
"uuid": "Q3f7CTSfScCLTUCBKURzCw",
"pri": "1",
"rep": "1",
"docs.count": "0",
"docs.deleted": "0",
"store.size": "416b",
"pri.store.size": "208b"
},
{
"health": "green",
"index": "metricbeat-7.10.0-2020.11.24-000001",
"uuid": "j5hJlvknQliWmVvdLVSH7w",
"pri": "1",
"rep": "1",
"docs.count": "257315",
"docs.deleted": "0",
"store.size": "144.6mb",
"pri.store.size": "72.3mb"
},
{
"health": "green",
"index": "infinireindex",
"uuid": "lKLfKdswTqOjYmQrQehnQw",
"pri": "1",
"rep": "1",
"docs.count": "7",
"docs.deleted": "2",
"store.size": "285kb",
"pri.store.size": "127.5kb"
},
{
"health": "green",
"index": ".apm-custom-link",
"uuid": "3jcumkqTRJi7PhsLLSwklw",
"pri": "1",
"rep": "1",
"docs.count": "0",
"docs.deleted": "0",
"store.size": "416b",
"pri.store.size": "208b"
},
{
"health": "green",
"index": "gateway_requests",
"uuid": "C0j0942KR6muJMHyagG2AQ",
"pri": "1",
"rep": "1",
"docs.count": "17961",
"docs.deleted": "0",
"store.size": "109.9mb",
"pri.store.size": "54.9mb"
},
{
"health": "yellow",
"index": ".kibana_task_manager_1",
"uuid": "uiVESvY_TiedZ5LuQLWxuw",
"pri": "1",
"rep": "1",
"docs.count": "5",
"docs.deleted": "10455",
"store.size": "2.6mb",
"pri.store.size": "2.6mb"
},
{
"health": "green",
"index": "infini-test1",
"uuid": "mVxvSFwSRBmxQx8tvIf7Jw",
"pri": "1",
"rep": "1",
"docs.count": "5",
"docs.deleted": "2",
"store.size": "48.1kb",
"pri.store.size": "29.3kb"
},
{
"health": "green",
"index": "dict",
"uuid": "F6vp1k_XRn-FmXoHOsBl2Q",
"pri": "1",
"rep": "1",
"docs.count": "8",
"docs.deleted": "1",
"store.size": "301.4kb",
"pri.store.size": "149.4kb"
},
{
"health": "green",
"index": ".kibana-event-log-7.10.0-000001",
"uuid": "ZhsJvWMeT9S0BzRhHzVr6Q",
"pri": "1",
"rep": "1",
"docs.count": "16",
"docs.deleted": "0",
"store.size": "79.9kb",
"pri.store.size": "39.9kb"
},
{
"health": "green",
"index": "infini-test",
"uuid": "eFLziuhBQ02ErA0n58-2hg",
"pri": "1",
"rep": "1",
"docs.count": "11",
"docs.deleted": "4",
"store.size": "86.3kb",
"pri.store.size": "43.1kb"
},
{
"health": "green",
"index": "mock_log",
"uuid": "NI7ntH_YRHapvjqB30LFQA",
"pri": "1",
"rep": "1",
"docs.count": "45806",
"docs.deleted": "0",
"store.size": "4.1mb",
"pri.store.size": "2mb"
},
{
"health": "green",
"index": ".async-search",
"uuid": "1ygzjQtgQDyksA7CDAeZxw",
"pri": "1",
"rep": "1",
"docs.count": "0",
"docs.deleted": "0",
"store.size": "462b",
"pri.store.size": "231b"
},
{
"health": "green",
"index": "infini-test8",
"uuid": "Uwj8JfmIRrOWQs1KT-pn9A",
"pri": "1",
"rep": "1",
"docs.count": "16",
"docs.deleted": "4",
"store.size": "35.4kb",
"pri.store.size": "17.7kb"
},
{
"health": "green",
"index": ".kibana-event-log-7.10.0-000002",
"uuid": "DyUerTJJR5Cy1HslL5qN8w",
"pri": "1",
"rep": "1",
"docs.count": "1",
"docs.deleted": "0",
"store.size": "11.2kb",
"pri.store.size": "5.6kb"
},
{
"health": "green",
"index": "infini-dict",
"uuid": "606XUzqLQFOna39joQFhlQ",
"pri": "1",
"rep": "1",
"docs.count": "8",
"docs.deleted": "1",
"store.size": "264.8kb",
"pri.store.size": "132.4kb"
}
],
"status": true
};
const mappings = {
@ -45875,10 +46093,10 @@ const mappings = {
};
export default {
// 'get /_search-center/indices/_cat': function(req, res){
// res.send(data)
// },
// 'get /_search-center/indices/_mappings/:index': function(req, res){
// res.send(mappings)
// }
'get /_search-center/_cat/indices': function(req, res){
res.send(data)
},
'get /_search-center/index/:index/_mappings': function(req, res){
res.send(mappings)
}
}

View File

@ -1,10 +1,92 @@
let data = {
"errmsg": "",
"errno": "0",
"payload": {
"data": [
"took": 0,
"timed_out": false,
"hits": {
"total": {
"relation": "eq",
"value": 7
},
"max_score": 0,
"hits": [
{
"_index": "infinireindex",
"_type": "_doc",
"_id": "bvrdoldath27go6rq64g",
"_source": {
"created_at": "2021-01-07T18:03:01.769901+08:00",
"desc": "",
"dest": {
"index": "infini-test8",
"pipeline": ""
},
"id": "bvrdoldath27go6rq64g",
"name": "test ddd",
"source": {
"_source": [],
"index": "infini-test",
"query": null
},
"status": "SUCCEED",
"task_id": "F0D6OfeVSzuMhf5528ANTw:1050387",
"task_source": {
"completed": true,
"response": {
"batches": 1,
"created": 0,
"deleted": 0,
"failures": [],
"noops": 0,
"requests_per_second": -1,
"retries": {
"bulk": 0,
"search": 0
},
"throttled": "0s",
"throttled_millis": 0,
"throttled_until": "0s",
"throttled_until_millis": 0,
"timed_out": false,
"took": 79,
"total": 11,
"updated": 11,
"version_conflicts": 0
},
"task": {
"action": "indices:data/write/reindex",
"cancellable": true,
"description": "reindex from [infini-test] to [infini-test8][_doc]",
"headers": {},
"id": 1050387,
"node": "F0D6OfeVSzuMhf5528ANTw",
"running_time_in_nanos": 79494026,
"start_time_in_millis": 1610013781769,
"status": {
"batches": 1,
"created": 0,
"deleted": 0,
"noops": 0,
"requests_per_second": -1,
"retries": {
"bulk": 0,
"search": 0
},
"throttled_millis": 0,
"throttled_until_millis": 0,
"total": 11,
"updated": 11,
"version_conflicts": 0
},
"type": "transport"
}
}
}
},
{
"_index": "infinireindex",
"_type": "_doc",
"_id": "bvqmpstath24tgfo107g",
"_source": {
"created_at": "2021-01-06T15:55:31.426604+08:00",
"desc": "test source index not exists",
"dest": {
@ -58,9 +140,13 @@ let data = {
"type": "transport"
}
}
}
},
{
"_index": "infinireindex",
"_type": "_doc",
"_id": "bvqmmnlath24tgfo1070",
"_source": {
"created_at": "2021-01-06T15:48:46.585112+08:00",
"desc": "test query param again",
"dest": {
@ -131,9 +217,13 @@ let data = {
"type": "transport"
}
}
}
},
{
"_index": "infinireindex",
"_type": "_doc",
"_id": "bvqmlf5ath24tgfo106g",
"_source": {
"created_at": "2021-01-06T15:46:04.745132+08:00",
"desc": "test query param",
"dest": {
@ -204,9 +294,13 @@ let data = {
"type": "transport"
}
}
}
},
{
"_index": "infinireindex",
"_type": "_doc",
"_id": "bvqmkilath24tgfo1060",
"_source": {
"created_at": "2021-01-06T15:44:10.535851+08:00",
"desc": "test source param",
"dest": {
@ -278,9 +372,13 @@ let data = {
"type": "transport"
}
}
}
},
{
"_index": "infinireindex",
"_type": "_doc",
"_id": "bvqmj55ath24tgfo105g",
"_source": {
"created_at": "2021-01-06T15:41:08.159721+08:00",
"desc": "test pipeline param",
"dest": {
@ -347,9 +445,13 @@ let data = {
"type": "transport"
}
}
}
},
{
"_index": "infinireindex",
"_type": "_doc",
"_id": "bvq89p5ath243f63hngg",
"_source": {
"created_at": "2021-01-05T23:25:24.751473+08:00",
"desc": "test new rebuild api",
"dest": {
@ -417,16 +519,15 @@ let data = {
}
}
}
],
"total": {
"relation": "eq",
"value": 6
}
]
}
},
"status": true
};
export default {
// 'get /_search-center/rebuild/list': function(req, res){
// res.send(data)
// }
'get /_search-center/rebuild/_search': function(req, res){
res.send(data)
}
}

View File

@ -4,10 +4,7 @@ import {pathPrefix} from './common';
export async function getDocList(params) {
return request(`${pathPrefix}/doc/${params.index}/_search`, {
method: 'POST',
body: {
action: 'SEARCH',
...params,
},
body: params,
});
}
@ -21,6 +18,7 @@ export async function saveDoc(params) {
export async function deleteDoc(params) {
return request(`${pathPrefix}/doc/${params.index}/${params.data.id}`, {
method: 'DELETE',
body: ['testid1', 'testid2'],
});
}