adjust document query args
This commit is contained in:
parent
e359650a1b
commit
5e685f47c7
|
@ -11,8 +11,8 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type docReqBody struct {
|
type docReqBody struct {
|
||||||
PageIndex int `json:"pageIndex"`
|
From int `json:"from"`
|
||||||
PageSize int `json:"pageSize"`
|
Size int `json:"size"`
|
||||||
Filter string `json:"filter"`
|
Filter string `json:"filter"`
|
||||||
Cluster string `json:"cluster"`
|
Cluster string `json:"cluster"`
|
||||||
Keyword string `json:"keyword"`
|
Keyword string `json:"keyword"`
|
||||||
|
@ -111,17 +111,14 @@ func (handler APIHandler) HandleSearchDocumentAction(w http.ResponseWriter, req
|
||||||
}
|
}
|
||||||
indexName := ps.ByName("index")
|
indexName := ps.ByName("index")
|
||||||
var (
|
var (
|
||||||
pageSize = 10
|
|
||||||
pageIndex = 1
|
|
||||||
sort = ""
|
sort = ""
|
||||||
)
|
)
|
||||||
if reqBody.PageSize > 0 {
|
if reqBody.From < 0 {
|
||||||
pageSize = reqBody.PageSize
|
reqBody.From = 0
|
||||||
}
|
}
|
||||||
if reqBody.PageIndex > 0 {
|
if reqBody.Size <= 0 {
|
||||||
pageIndex = reqBody.PageIndex
|
reqBody.Size = 10
|
||||||
}
|
}
|
||||||
from := (pageIndex - 1) * pageSize
|
|
||||||
filter := `{"match_all": {}}`
|
filter := `{"match_all": {}}`
|
||||||
if reqBody.Keyword != "" {
|
if reqBody.Keyword != "" {
|
||||||
filter = fmt.Sprintf(`{"query_string":{"query":"%s"}}`, reqBody.Keyword)
|
filter = fmt.Sprintf(`{"query_string":{"query":"%s"}}`, reqBody.Keyword)
|
||||||
|
@ -136,7 +133,7 @@ func (handler APIHandler) HandleSearchDocumentAction(w http.ResponseWriter, req
|
||||||
}
|
}
|
||||||
sort = fmt.Sprintf(`"%s":{"order":"%s"}`, sortField, sortDirection)
|
sort = fmt.Sprintf(`"%s":{"order":"%s"}`, sortField, sortDirection)
|
||||||
}
|
}
|
||||||
query := fmt.Sprintf(`{"from":%d, "size": %d, "query": %s, "sort": [{%s}]}`, from, pageSize, filter, sort)
|
query := fmt.Sprintf(`{"from":%d, "size": %d, "query": %s, "sort": [{%s}]}`, reqBody.From, reqBody.Size, filter, sort)
|
||||||
//fmt.Println(indexName, query)
|
//fmt.Println(indexName, query)
|
||||||
var reqBytes = []byte(query)
|
var reqBytes = []byte(query)
|
||||||
resp, err := client.SearchWithRawQueryDSL(indexName, reqBytes)
|
resp, err := client.SearchWithRawQueryDSL(indexName, reqBytes)
|
||||||
|
|
|
@ -45,7 +45,7 @@ export default {
|
||||||
isLoading: true,
|
isLoading: true,
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
let res = yield call(getDocList, payload);
|
let res = yield call(getDocList, _.clone(payload));
|
||||||
if(res.status === false){
|
if(res.status === false){
|
||||||
message.warn("加载数据失败")
|
message.warn("加载数据失败")
|
||||||
yield put({
|
yield put({
|
||||||
|
|
|
@ -2,6 +2,10 @@ import request from '@/utils/request';
|
||||||
import {pathPrefix} from './common';
|
import {pathPrefix} from './common';
|
||||||
|
|
||||||
export async function getDocList(params) {
|
export async function getDocList(params) {
|
||||||
|
params.from = (params.pageIndex - 1) * params.pageSize;
|
||||||
|
params.size = params.pageSize;
|
||||||
|
delete params.pageSize;
|
||||||
|
delete params.pageIndex;
|
||||||
return request(`${pathPrefix}/doc/${params.index}/_search`, {
|
return request(`${pathPrefix}/doc/${params.index}/_search`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: params,
|
body: params,
|
||||||
|
|
Loading…
Reference in New Issue