filter,range的使用,以下表示时间范围为2019-04-01 00:00:00
到2019-04-03 23:59:59
# GET my_index/_search
{
"query": {
"bool": {
"filter": [
{
"range": {
"time": {
"gte": "2019-04-04||/M",
"lt": "2019-04-04"
}
}
}
]
}
}
}
搜索两个月前的“今天”的数据并按时间由最新到最老排序
# GET myidx/_search
{
"sort": [
{
"time": {
"order": "desc"
}
}
],
"query": {
"bool": {
"filter": [
{
"range": {
"time": {
"gte": "now-2M/d",
"lt": "now-2M+1d/d",
"time_zone": "UTC"
}
}
}
]
}
}
}
:::tips
"lt": "now-2M+1d/d"
也可以换成"lte": "now-2M/d"
:::
多个filed的搜索
# GET myidx/_search
{
"query": {
"bool": {
"filter": [
{
"term": {
"event_type": "install"
}
}, {
"term": {
"event_date": "2019-04-22"
}
}
]
}
}
}