过滤器聚合不起作用弹性搜索

时间:2020-05-01 19:49:26

标签: elasticsearch spring-data

我正在尝试使用过滤器聚合来支持前端的多选构面值。

我有颜色和深度滤镜。

滤色器包含以下值:黑色(5),蓝色(3),红色(2)

深度滤镜拥有的值:70mm(3),60mm(5),50mm(3)

当我在彩色滤光片中选择“黑色”时,其他所有选项(蓝色,红色)都没有响应。

我尝试通过添加

"colourAgg": {
        "filter": {
            "match_all": {
                "boost": 1.0
            }
        },
        "aggregations": {
            "colourAgg": {
                "terms": {
                    "field": "colour.keyword",
                    "size": 10,
                    "min_doc_count": 1,
                    "shard_min_doc_count": 0,
                    "show_term_doc_count_error": false,
                    "order": [
                        {
                            "_count": "desc"
                        },
                        {
                            "_key": "asc"
                        }
                    ]
                }
            }
        }
    }

映射:

{
"products": {
    "mappings": {
        "properties": {
            "assemblyrequired": {
                "type": "boolean"
            },
            "australianmade": {
                "type": "boolean"
            },
            "australiasellable": {
                "type": "boolean"
            },
            "avgRating": {
                "type": "float"
            },
            "category": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel1": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel2": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categorylevel3": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "categoryname": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "colour": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "commercialuse": {
                "type": "boolean"
            },
            "customisable": {
                "type": "boolean"
            },
            "depth": {
                "type": "float"
            },
            "freedelivery": {
                "type": "boolean"
            },
            "height": {
                "type": "float"
            },
            "listprice": {
                "type": "float"
            },
            "materialcode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "moneybackguarantee": {
                "type": "boolean"
            },
            "newrelease": {
                "type": "boolean"
            },
            "numberOfRating": {
                "type": "long"
            },
            "online": {
                "type": "boolean"
            },
            "outdooruse": {
                "type": "boolean"
            },
            "predictivecategorydata": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "pricematchguarantee": {
                "type": "boolean"
            },
            "productid": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "productimageurl": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "productname": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "producttypecode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "promotedprice": {
                "type": "float"
            },
            "sale": {
                "type": "integer"
            },
            "saleprice": {
                "type": "float"
            },
            "sellable": {
                "type": "boolean"
            },
            "sellercode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "shortdescription": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "sku": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "state": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "stylecode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "warrantycode": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "weight": {
                "type": "float"
            },
            "width": {
                "type": "float"
            }
        }
    }
}

}

文档:

{
                "sellercode": "F2OVRX",
                "productid": 13410,
                "saleprice": 4000.2,
                "producttypecode": "Recliner Lounge or Sofa",
                "productimageurl": null,
                "sellable": false,
                "freedelivery": false,
                "promotedprice": null,
                "listprice": 4000.2,
                "productname": "louise chair - cream",
                "outdooruse": null,
                "avgRating": 0.0,
                "warrantycode": null,
                "state": [
                    "SA",
                    "NT"
                ],
                "newrelease": null,
                "sku": "VSTALDBED415_8",
                "height": 66.0,
                "shortdescription": "Stackable light weight chair made from Virgin materials.High strength one piece gas injection moulded technology.160kg weight tested, Catas test certificated",
                "commercialuse": true,
                "customisable": true,
                "weight": null,
                "pricematchguarantee": true,
                "colour": "Black",
                "australianmade": true,
                "depth": 65.0,
                "moneybackguarantee": false,
                "width": 31.0,
                "predictivecategorydata": [
                    "Dressing Table-Dining Table-52"
                ],
                "online": true,
                "materialcode": "Timber",
                "numberOfRating": 0,
                "categoryname": [
                    "Bed - Double",
                    "Dining Table",
                    "Dressing Table",
                    "444",
                    "Bench",
                    null,
                    "M13",
                    "Bed Head"
                ],
                "location": [],
                "assemblyrequired": null,
                "category": [
                    "outdoor",
                    "bed",
                    "doublebeds",
                    "444",
                    "beds",
                    "cat1220",
                    "m13",
                    "cafebarrestaurant"
                ],
                "stylecode": "Safari"
            }

但是我仍然只有黑色。有输入吗?

谢谢, 斯里。

1 个答案:

答案 0 :(得分:1)

聚合处理“查询”部分返回的文档。因此,如果您要在查询中过滤“黑色”,则将返回所有黑色的文档,并对这些文档应用汇总。

您需要将汇总应用于索引中的所有文档,而不仅仅是查询返回的文档。您可以为此使用Global aggregation

在搜索中定义所有文档的单个存储桶 执行上下文。此上下文由索引和 您正在搜索的文档类型,但不受文档类型的影响 搜索查询本身。

:
相关问题