Aggregation on top N results

后端 未结 3 1879
感动是毒
感动是毒 2020-12-19 09:55

Problem:

If I search for \"iphone\" I get 400 product results and the product category aggregation I have returns the top 3 categories in the result

3条回答
  •  爱一瞬间的悲伤
    2020-12-19 10:16

    You are looking for Sampler Aggregation. I have a similar answer at Aggregation on top n results

    {
      "aggs": {
        "bestDocs": {
           "sampler": {
                "shard_size":100
             },
           "aggs": {
              "product_categories": {
                 "terms": {
                    "field": "product_category",
                    "size": 3
                 }
              }
           } 
       }
    }
    

    It will take the top 100 docs sorted by their scores and then do term aggregation.

提交回复
热议问题