Skip to content
项目
群组
代码片段
帮助
正在加载...
帮助
为 GitLab 提交贡献
登录
切换导航
L
library
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
计划
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
stbz
library
Commits
68db1e7c
提交
68db1e7c
authored
3月 30, 2022
作者:
limeng
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加拆分逻辑 为私有化使用 后续优化
上级
c61dd6b2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
66 行增加
和
0 行删除
+66
-0
service.go
elastic/service.go
+57
-0
struct.go
elastic/struct.go
+9
-0
没有找到文件。
elastic/service.go
浏览文件 @
68db1e7c
...
@@ -84,7 +84,64 @@ func GetList(req GetListReq) (searchResult *elastic.SearchResult,err error) {
...
@@ -84,7 +84,64 @@ func GetList(req GetListReq) (searchResult *elastic.SearchResult,err error) {
return
return
}
}
//获取搜索service 准备数据
func
GetSearchService
(
req
GetListReq
)
(
searchService
*
elastic
.
SearchService
,
err
error
)
{
//连接Es
client
,
err
:=
connection
()
if
err
!=
nil
||
client
==
nil
{
err
=
errors
.
New
(
"elastic连接失败"
+
err
.
Error
())
return
}
defer
client
.
Stop
()
_
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
defer
cancel
()
//准备查询条件
searchService
=
client
.
Search
()
.
Index
(
req
.
IndexName
)
.
Pretty
(
true
)
.
Query
(
req
.
Condition
)
return
}
func
DoSearchService
(
req
DoSearchServiceReq
)
(
searchResult
*
elastic
.
SearchResult
,
err
error
)
{
//检测是from_size查询还是search_after滚动式查询
isSearchAfter
,
from
,
size
:=
checkDoParam
(
req
)
//连接Es
client
,
err
:=
connection
()
if
err
!=
nil
||
client
==
nil
{
err
=
errors
.
New
(
"elastic连接失败"
+
err
.
Error
())
return
}
defer
client
.
Stop
()
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
5
*
time
.
Second
)
defer
cancel
()
//准备查询条件
if
isSearchAfter
==
false
{
//分页查询Es
searchResult
,
err
=
req
.
SearchService
.
From
(
from
)
.
Size
(
size
)
.
Do
(
ctx
)
}
if
isSearchAfter
==
true
{
//滚动式查询Es
searchResult
,
err
=
req
.
SearchService
.
SearchAfter
(
req
.
SearchAfter
.
Value
)
.
From
(
from
)
.
Size
(
size
)
.
Sort
(
req
.
SearchAfter
.
SortField
.
Field
,
req
.
SearchAfter
.
SortField
.
Sort
)
.
Do
(
ctx
)
}
return
}
//检验参数 区分 分页查询 滚动式查询
func
checkDoParam
(
req
DoSearchServiceReq
)
(
isSearchAfter
bool
,
from
int
,
size
int
)
{
if
req
.
Page
!=
0
&&
req
.
Limit
!=
0
{
from
=
(
req
.
Page
-
1
)
*
req
.
Limit
size
=
req
.
Limit
}
if
req
.
SearchAfter
!=
nil
{
from
=
0
size
=
50
isSearchAfter
=
true
}
return
}
//检验参数 区分 分页查询 滚动式查询
//检验参数 区分 分页查询 滚动式查询
func
checkParam
(
req
GetListReq
)
(
isSearchAfter
bool
,
from
int
,
size
int
)
{
func
checkParam
(
req
GetListReq
)
(
isSearchAfter
bool
,
from
int
,
size
int
)
{
if
req
.
Page
!=
0
&&
req
.
Limit
!=
0
{
if
req
.
Page
!=
0
&&
req
.
Limit
!=
0
{
...
...
elastic/struct.go
浏览文件 @
68db1e7c
...
@@ -35,6 +35,15 @@ type GetListReq struct {
...
@@ -35,6 +35,15 @@ type GetListReq struct {
SearchAfter
*
SearchAfter
`json:"search_after"`
SearchAfter
*
SearchAfter
`json:"search_after"`
IndexName
string
`json:"index_name"`
IndexName
string
`json:"index_name"`
}
type
DoSearchServiceReq
struct
{
SearchService
*
elastic
.
SearchService
Page
int
`json:"page"`
Limit
int
`json:"limit"`
SearchAfter
*
SearchAfter
`json:"search_after"`
IndexName
string
`json:"index_name"`
}
}
type
SearchAfter
struct
{
type
SearchAfter
struct
{
SortField
struct
{
SortField
struct
{
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论