es数据库,must和should嵌套使用和分组统计
must和should嵌套使用
"query": {
"bool": {
"must": [
{
"bool": {
"should": [
{"match": {"look_user": "test1"}},
{"match": {"userId": "test2"}}
]
}
},
{"terms": {"status": 1}},
{"match": {"verify": 2}}
]
}
}
- 意义:表示(look_user=test1 or userId=test2) and status = 1 and verify = 2
分组统计
单值统计
{
"size": 0,
"aggs": {
"name_type": {
"terms": {
"field": "class"
}
}
}
}
多层嵌套统计
{
"size": 0,
"aggs": {
"name_type": {
"terms": {
"field": "class"
},
"aggs": {
"_B_": {
"terms": {
"field": "tag"
}
}
}
}
}
}
按时间统计
body = {
"query": { # 按时间范围查找
"range": {
"save_time": {
"gte": "2022-06-01",
"lt": "2022-06-04"
}
}
},
"size": 0,
"aggs": {
"groupDate": {
"date_histogram": {
"field": "save_time",
"interval": "day", # 按时间分天统计,year, quarter, month, week, day, hour, minute, second(年份、季度、月、周、日、小时、分钟、秒)
"format": "yyyy-MM-dd"
}
}
}
}
- 意义:在 2022-06-01 到2022-06-04之间,统计每天更新数据数据