前两篇介绍了es的简单条件查询,本文将在条件查询的基础上添加聚合条件进行查询,聚合查询很大的不同是在查询结果的解析上。
首先看一下这条dsl查询语句:
GET test*/_search
{
"size": 0,
"timeout": "60s",
"query": {
"bool": {
"must": [
{
"terms": {
"server_name.keyword": [
"www.test.com"
],
"boost": 1
}
},
{
"match_phrase": {
"args": {
"query": "786754748671257",
"slop": 0,
"zero_terms_query": "NONE",
"boost": 1
}
}
},
{
"range": {
"@timestamp": {
"from": "2020-06-04T16:00:00.000Z",
"to": "2020-06-04T18:00:00.000Z",
"include_lower": true,
"include_upper": false,
"boost": 1
}
}
}
],
"adjust_pure_negative": true,
"boost": 1
}
},
"aggregations": {
"@timestamp": {
"date_histogram": {
"field": "@timestamp",
"interval": "1h",
"offset": 0,
"order": {
"_key": "asc"
},
"keyed": false,
"min_doc_count": 0
},
"aggregations": {
"args": {
"terms": {
"field": "args.keyword",
"min_doc_count": 100,
"shard_min_doc_count": 0,
"show_term_doc_count_error": false,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
}
}
}
},
"track_total_hits": "true"
}
接下来的代码绑定查询条件部分都会围绕这条语句来写
再看一下这条语句的查询结果:
{
"took" : 42,
"timed_out" : false,
"_shards"