[英]Global term aggregation with filtered count - Elasticsearch 5
我将产品存储在ES中,并尝试按产品大小进行汇总。 我想设计以下行为。 对于甚至查询之外的每个术语,也可以根据查询接收术语计数。
因此,查询尺寸[“ S”,“ M”]我希望收到:
S:1
M:1
L:0
这可能吗?
这是我的设置,得到以下结果:
S:1
M:1
但是L完全不见了。
PUT demo
{
"mappings": {
"product": {
"properties": {
"size": {
"type": "keyword"
}
}
}
}
}
PUT demo/product/1
{
"size": "S"
}
PUT demo/product/2
{
"size": "M"
}
PUT demo/product/3
{
"size": "L"
}
GET demo/_search
{
"size": 0,
"query": {
"bool": {
"must": [
{
"terms": {
"size": [
"S",
"M"
]
}
}
]
}
},
"aggs": {
"size": {
"terms": {
"field": "size"
}
}
}
}
您可以使用过滤器。
{
"size": 0,
"query": {
"bool": {
"must": [
{ "terms": { "field": "size" } }
],
"filter": {
"terms": { "size": [ "S", "M"] }
}
}
},
"aggs": {
"size": {
"terms": { "field": "size" }
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.