【发布时间】:2019-01-25 22:11:34
【问题描述】:
我有这样的“嵌套”映射:
"stringAttributes":{
"type":"nested",
"properties":{
"Name":{
"type":"keyword"
},
"Value":{
"type":"keyword"
}
}
},
因此有如下文档:
stringAttributes:[
{
Name:"supplier",
Value:"boohoo"
},
{
Name:"brand",
Value:"gucci"
},
{
Name:"primaryColour",
Value:"black"
},
{
Name:"secondaryColour",
Value:"green"
},
{
Name:"size",
Value:"12"
}
]
在构建多面搜索时,我相信我需要一个全局聚合。 IE。当一个供应商被用户过滤时,结果集将不包含来自其他供应商的文档,因此常规聚合将不包含任何其他供应商。
查询可以包括以下子句:
"must": [
{
"nested": {
"path": "stringAttributes",
"query": {
"bool": {
"must": [
{
"term": {
"stringAttributes.Name": "supplier"
}
},
{
"terms": {
"stringAttributes.Value": [
"boohoo"
]
}
}
]
}
}
}
},
{
"nested": {
"path": "stringAttributes",
"query": {
"bool": {
"must": [
{
"term": {
"stringAttributes.Name": "brand"
}
},
{
"terms": {
"stringAttributes.Value": [
"warehouse"
]
}
}
]
}
}
}
}
]
因此,在这种情况下,我需要一个全局聚合,然后由应用的所有其他过滤器(例如按品牌)过滤,这将返回在给定这些其他过滤器的情况下可以选择的其他供应商。
这是我目前所拥有的。但是,它返回“全局”未过滤的结果。在这一点上,我完全被难住了。
{
"global":{},
"aggs":{
"inner":{
"filter":{
"nested":{
"query":{
"bool":{
"filter":[
{
"term":{
"stringAttributes.Name":{
"value":"brand"
}
}
},
{
"terms":{
"stringAttributes.Value":[
"warehouse"
]
}
}
]
}
},
"path":"stringAttributes"
}
}
},
"aggs":{
"nested":{
"path":"stringAttributes"
},
"aggs":{
"aggs":{
"filter":{
"match":{
"stringAttributes.Name":"supplier"
}
},
"aggs":{
"facet_value":{
"terms":{
"size":1000,
"field":"stringAttributes.Value"
}
}
}
}
}
}
}
}
对于过滤具有嵌套属性的全局聚合有什么建议吗?我已经阅读了很多关于 SO 的各种其他答案的文档,但仍然难以理解为什么这个特定的 agg 没有被过滤。
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation