我正在寻找一个获得聚合的解决方案,每个字段之一,但是在不同的聚合中应用不同的查询条件。
我有一个产品集合,它具有属性:type、color、brand。用户选择:brand=Gap,color=White,type=Sandal。若要在每次聚合时显示各种类似产品的计数:
brand聚合的查询条件:color=White和type=Sandalcolor聚合的查询条件:brand=Gap和type=Sandaltype聚合的查询条件:brand=Gap和color=White这能在一个ElasticSearch查询中完成吗?
发布于 2017-05-19 01:40:49
您将为每个聚合创建三个带有filter agg的聚合,并在其中添加您想要的查询。我使用了最简单的方法-- bool和term --只是为了展示高层次的方法:
"aggs": {
"brand_agg": {
"filter": {
"bool": {
"must": [
{
"term": {
"color": "white"
}
},
{
"term": {
"type": "sandal"
}
}
]
}
}
},
"color_agg": {
"filter": {
"bool": {
"must": [
{
"term": {
"brand": "gap"
}
},
{
"term": {
"type": "sandal"
}
}
]
}
}
},
"type_agg": {
"filter": {
"bool": {
"must": [
{
"term": {
"color": "white"
}
},
{
"term": {
"brand": "gap"
}
}
]
}
}
}
}https://stackoverflow.com/questions/44055935
复制相似问题