logging: start_time and end_time are not required params
Signed-off-by: huanggze <loganhuang@yunify.com>
This commit is contained in:
@@ -119,14 +119,15 @@ func (bb *bodyBuilder) mainBool(sf logging.SearchFilter) *bodyBuilder {
|
||||
ms = append(ms, Match{Bool: &b})
|
||||
}
|
||||
|
||||
if !sf.Starttime.IsZero() || !sf.Endtime.IsZero() {
|
||||
fromTo := Match{
|
||||
Range: &Range{&Time{
|
||||
Gte: &sf.Starttime,
|
||||
Lte: &sf.Endtime,
|
||||
}},
|
||||
}
|
||||
ms = append(ms, fromTo)
|
||||
r := &Range{Time: &Time{}}
|
||||
if !sf.Starttime.IsZero() {
|
||||
r.Gte = &sf.Starttime
|
||||
}
|
||||
if !sf.Endtime.IsZero() {
|
||||
r.Lte = &sf.Endtime
|
||||
}
|
||||
if r.Lte != nil || r.Gte != nil {
|
||||
ms = append(ms, Match{Range: r})
|
||||
}
|
||||
|
||||
bb.Body.Query = &Query{Bool{Filter: ms}}
|
||||
|
||||
@@ -45,6 +45,12 @@ func TestMainBool(t *testing.T) {
|
||||
},
|
||||
expected: "api_body_4.json",
|
||||
},
|
||||
{
|
||||
filter: logging.SearchFilter{
|
||||
Starttime: time.Unix(1590744676, 0),
|
||||
},
|
||||
expected: "api_body_7.json",
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
|
||||
15
pkg/simple/client/logging/elasticsearch/testdata/api_body_7.json
vendored
Normal file
15
pkg/simple/client/logging/elasticsearch/testdata/api_body_7.json
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"query":{
|
||||
"bool":{
|
||||
"filter":[
|
||||
{
|
||||
"range":{
|
||||
"time":{
|
||||
"gte":"2020-05-29T17:31:16+08:00"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user