1. Classification of aggregation
2. DSL implements bucket aggregation
# 集合, 1、bucket terms
GET /hotel/_search
{
"size": 0,
"aggs": {
"brandAgg": {
"terms": {
"field": "brand",
"size": 20
}
}
}
}
3. Bucket aggregation-aggregation structure sorting
# 集合,2、bucket terms 排序
GET /hotel/_search
{
"size": 0,
"aggs": {
"brandAgg": {
"terms": {
"field": "brand",
"order": {
"_count": "asc"
},
"size": 20
}
}
}
}
4. Bucket aggregation - limit the scope of aggregation
# 集合,3、bucket terms 过滤
GET /hotel/_search
{
"size": 0,
"query": {
"range": {
"price": {
"gte": 0,
"lte": 200
}
}
},
"aggs": {
"brandAgg": {
"terms": {
"field": "brand",
"size": 20
}
}
}
}
5. DSL realizes Metrics aggregation
# 聚合,4、metrics
GET /hotel/_search
{
"size": 0,
"aggs": {
"brandAgg": {
"terms": {
"field": "brand",
"order": {
"score_stats.max": "asc"
},
"size": 10
},
"aggs": {
"score_stats": {
"stats": {
"field": "score"
}
}
}
}
}
}
6. Summary analysis
This chapter learns what aggregation is and the DSL syntax of Bucket and Metric aggregation
1. What is aggregation: aggregation is the statistics, analysis, and calculation of documents
2. Common aggregation: Bucket, Metric, Pipeline
3. Fields supported by aggregation: keyword, value, date, Boolean
4. Three elements of aggregation: aggregation name, aggregation type, aggregation field
The above content comes from dark horse programmers, and the learning rhythm of the course is gradual. I think it is very good after studying, and friends who are interested should not miss it.