簡體   English   中英

過濾聚合不起作用彈性搜索

[英]filter aggregation not working elastic search

我正在嘗試使用過濾器聚合來支持來自前端的多選構面值。

我有顏色和深度過濾器。

濾色器保存值:黑色(5),藍色(3),紅色(2)

深度過濾器保持值:70mm(3),60mm(5),50mm(3)

當我 select 時,彩色濾光片中的黑色所有其他選項(藍色、紅色)都沒有響應。

我試過添加

"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"
            }

但我仍然只得到黑色。任何輸入?

謝謝,斯里。

聚合處理“查詢”部分返回的文檔。 因此,如果您在查詢中過濾“黑色”,則將返回所有帶有黑色的文檔,並且將在這些文檔上應用聚合。

您需要將聚合應用於索引中的所有文檔,而不僅僅是查詢返回的文檔。 您可以為此使用全局聚合

定義搜索執行上下文中所有文檔的單個存儲桶。 此上下文由您正在搜索的索引和文檔類型定義,但不受搜索查詢本身的影響。

{
  "aggs": {
    "products": {
      "global": {}, --> note
      "aggs": {
        "filtered_docs": {   --> filter certain docs for entire index 
          "filter": {
            "range": {
              "depth": {
                "gte": 60
              }
            }
          },
          "aggs": {
            "colourAgg": {   --> facets for color
              "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"
                  }
                ]
              }
            }
          }
        }
      }
    }
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM