标签:价格 query 指定 tag 名称 排序 均值 from esc
将文本field的fielddata属性设置为true,才能聚合PUT /ecommerce/_mapping/product
{
"properties": {
"tags": {
"type": "text",
"fielddata": true
}
}
}
GET /ecommerce/product/_search
{
"size": 0,
"aggs":{
"group_by_tags":{
"terms": {
"field": "tags"
}
}
}
}
GET /ecommerce/product/_search
{
"size": 0,
"query": {
"match": {
"name": "yagao"
}
},
"aggs":{
"group_by_tags":{
"terms": {
"field": "tags"
}
}
}
}
GET /ecommerce/product/_search
{
"size": 0,
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags"
},
"aggs": {
"arg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
GET /ecommerce/product/_search
{
"size": 0,
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags",
"order": {
"arg_price": "desc"
}
},
"aggs": {
"arg_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": 60
}
]
},
"aggs": {
"group_by_tags": {
"terms": {
"field": "tags"
},
"aggs": {
"avg_price": {
"avg": {
"field": "price"
}
}
}
}
}
}
}
}
标签:价格 query 指定 tag 名称 排序 均值 from esc
原文地址:https://blog.51cto.com/395469372/2412343