请求 elk 的 post 参数是这个 json,两个 term,不同的 value,不知道是我写的这个结构体的有问题还是初始化有问题。求解怎么初始化?
- 原始 json
{
"_source": {
"excludes": [
"offset",
"*type",
"beat",
"*timestamp"
]
},
"query": {
"bool": {
"filter": [
{
"term": {
"loglvl.keyword": "ERROR"
}
},
{
"term": {
"module": "demo"
}
},
{
"range": {
"logtime": {
"gte": "2017-10-20T09:45:35.015+0800",
"lte": "2017-10-24T09:45:35.015+0800"
}
}
}
]
}
}
}
- 定义的结构体
type RequestValue struct {
Source struct {
Excludes []string `json:"excludes"`
} `json:"_source"`
Query struct {
Bool struct {
Filter []struct {
Term struct {
LoglvlKeyword string `json:"loglvl.keyword,omitempty"`
Module string `json:"module,omitempty"`
} `json:"term,omitempty"`
Range struct {
Logtime struct {
Gte string `json:"gte"`
Lte string `json:"lte"`
} `json:"logtime"`
} `json:"range,omitempty"`
} `json:"filter"`
} `json:"bool"`
} `json:"query"`
}
我这么初始化,想写一个当前时间的 Gte 的 value。
model.RequestValue{
Source: {
Excludes: {"offset", "*type", "beat", "*timestamp"}
},
Query: {
Bool: {
Filter: {
{Term: {LoglvlKeyword: "ERROR"}},
{Term: {Module: "demo"}},
{Range: {Logtime: {Gte: "2017-10-20T09:45:35.015+0800",
Lte: "2017-10-24T09:45:35.015+0800"
},},}
},
},
},
}