提交 5bed5c35 authored 作者: limeng's avatar limeng

修改排序

上级 cb20e51a
......@@ -66,7 +66,7 @@ func GetList(req GetListReq) (searchResult *elastic.SearchResult,err error) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
//准备查询条件
searchService := client.Search().Index(req.IndexName).Pretty(true).Query(req.Condition)
searchService := client.Search().Index(req.IndexName).Pretty(true).Query(req.Condition).Sort(req.SortField.Field, req.SortField.Sort)
if isSearchAfter == false {
//分页查询Es
......@@ -78,7 +78,7 @@ func GetList(req GetListReq) (searchResult *elastic.SearchResult,err error) {
searchResult, err = searchService.
SearchAfter(req.SearchAfter.Value).
From(from).Size(size).
Sort(req.SearchAfter.SortField.Field, req.SearchAfter.SortField.Sort).
Sort(req.SortField.Field, req.SortField.Sort).
Do(ctx)
}
......@@ -123,7 +123,7 @@ func DoSearchService(req DoSearchServiceReq) (searchResult *elastic.SearchResult
searchResult, err = req.SearchService.
SearchAfter(req.SearchAfter.Value).
From(from).Size(size).
Sort(req.SearchAfter.SortField.Field, req.SearchAfter.SortField.Sort).
Sort(req.SortField.Field, req.SortField.Sort).
Do(ctx)
}
......
......@@ -34,6 +34,10 @@ type GetListReq struct {
Limit int `json:"limit"`
SearchAfter *SearchAfter `json:"search_after"`
IndexName string `json:"index_name"`
SortField struct{
Field string `json:"field"`
Sort bool `json:"sort" `
} `json:"sort_field"`
}
......@@ -43,12 +47,12 @@ type DoSearchServiceReq struct {
Limit int `json:"limit"`
SearchAfter *SearchAfter `json:"search_after"`
IndexName string `json:"index_name"`
}
type SearchAfter struct {
SortField struct{
Field string `json:"field"`
Sort bool `json:"sort" `
} `json:"sort_field"`
}
type SearchAfter struct {
Value int `json:"value"`
}
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论