elasticsearch 多个搜索和过滤器数据返回nestjs mongodb中每个过滤器的计数

goqiplq2  于 2022-11-02  发布在  ElasticSearch
关注(0)|答案(1)|浏览(218)

我想按字段筛选数据库中的项目,并返回每个筛选器的计数。Example is when I select to return specific brand names I want to see the number of brand name available.
有没有什么搜索服务可以让我使用,比如Azure搜索,或者有没有一种方法可以在NestJs和mongodb中实现它
这是数据库集合

{
  "brand": "Screaming Eagle, The Flight",
  "producer": "Screaming Eagle",
  "productionCountry": "America",
  "region": "Napa Valley",
  "appellation": "Oakville",
  "vintage": "2016",
  "grape": "Cabernet Sauvignon",
  "maturity": "25",
  "case": "3 bottles",
  "origin": "SECONDARYMARKET",
  "type": "Red"
},{
  "brand": "Joseph Phelps, Insignia",
  "producer": "Joseph Phelps",
  "productionCountry": "America",
  "region": "Napa Valley",
  "appellation": "St. Helena",
  "vintage": "2012",
  "grape": "Cabernet Sauvignon",
  "maturity": "25",
  "case": "6 bottles",
  "origin": "SECONDARYMARKET",
  "type": "Red"
},{
  "brand": "Joseph Phelps, Insignia",
  "producer": "Joseph Phelps",
  "productionCountry": "America",
  "region": "Napa Valley",
  "appellation": "St. Helena",
  "vintage": "2012",
  "grape": "Cabernet Sauvignon",
  "maturity": "25",
  "case": "6 bottles",
  "origin": "SECONDARYMARKET",
  "type": "Red"
},{
  "brand": "Continuum",
  "producer": "Continuum",
  "productionCountry": "America",
  "region": "Napa Valley",
  "appellation": "Oakville",
  "vintage": "2017",
  "grape": "Cabernet Sauvignon",
  "maturity": "26",
  "case": "6 bottles",
  "origin": "SECONDARYMARKET",
  "type": "Red"
},{
  "brand": "Continuum",
  "producer": "Continuum",
  "productionCountry": "America",
  "region": "Napa Valley",
  "appellation": "Oakville",
  "vintage": "2017",
  "grape": "Cabernet Sauvignon",
  "maturity": "26",
  "case": "6 bottles",
  "origin": "SECONDARYMARKET",
  "type": "Red"
}
rekjcdws

rekjcdws1#

在Azure认知搜索中,您必须将facetable设置为true,以获取您想要的字段的计数,例如brand,然后在查询"facets": ["brand"]中指定。
有关Azure搜索的详细信息,请参阅:https://learn.microsoft.com/en-us/azure/search/search-faceted-navigation
这在MongoDb中使用$facet聚合运算符工作,您可以在此处阅读更多信息:https://www.mongodb.com/docs/manual/reference/operator/aggregation/facet/

相关问题