标签:agg src tco 文本 match product size 显示 ldd
GET /ecommerce/product/_search
{
“aggs”:{
“group_by_tags”:{
“terms”:{“field”:”tags”}
}
}
}
将文本field的fielddate属性设置为true
PUT /ecommerce/_mapping/product
{
“properties”:{
“tags”:{
“type”:”text”,
“fielddata”:true
}
}
}
重新执行分组命令
“size”:0
可以不显示聚合分析数据的信息,只返回聚合分析之后的结果
GET /ecommerce/product/_search
{
"size": 0,
"query": {
"match": {
"name": "yagao"
}
},
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags"
}
}
}
}
结果一样,因为每个商品name中都包含有yagao
GET /ecommerce/product/_search
{
“size”:0,
“aggs”:{
“group_by_tags”:{
“terms”:{“fiedd”:”tags”},
“aggs”:{
“avg_price”:{
“avg”:{“field”:”price”}
}
}
}
}
}
GET /ecommerce/product/_search
{
“size”:0,
“aggs”:{
“group_by_tags”:{
“terms”:{“fiedd”:”tags”,“order”:{“avg_price”:”desc”}},
“aggs”:{
“avg_price”:{
“avg”:{“field”:”price”}
}
}
}
}
}
GET /ecommerce/product/_search
{
"size": 0,
"aggs": {
"group_by_price": {
"range": {
"field": "price",
"ranges": [
{
"from": 0,
"to": 20
},
{
"from": 20,
"to": 40
},
{
"from": 40,
"to": 50
}
]
},
"aggs": {
"group_by_tag": {
"terms": {
"field": "tags",
"order": {
"avg_by_price": "desc"
}
},
"aggs": {
"avg_by_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
Elasticsearch 顶尖高手(6)--快速入门案例实战:group by + avg + sort等聚合分析(三)
标签:agg src tco 文本 match product size 显示 ldd
原文地址:https://www.cnblogs.com/Mr-WangYue/p/11518866.html