Elasticsearch Group по агрегатам дает только 10 лучших результатов - PullRequest
0 голосов
/ 10 мая 2018

Я новичок в упругом поиске, и я пытался получить результаты с наибольшим количеством хитов
но это только дало мне 10 лучших результатов, как я могу сделать пагинацию в группе по совокупности.

вот мой запрос, который я отправляю

{
  "query": {
    "bool": {
      "must": [
        {
          "match_phrase_prefix": {
            "title": "Fortune"
          }
        }
      ]
    }
  },
  "aggs": {
    "by_district": {
      "terms": {
        "field": "product_id"
      },
      "aggs": {
        "tops": {
          "top_hits": {
            "size": 1
          }
        }
      }
    }
  },
  "from": 0,
  "size": 0
}  

что я получу в результате

{
  "took": 13,
  "timed_out": false,
  "_shards": {
    "total": 5,
    "successful": 5,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": 32,
    "max_score": 0,
    "hits": [

    ]
  },
  "aggregations": {
    "by_district": {
      "doc_count_error_upper_bound": 0,
      "sum_other_doc_count": 7,
      "buckets": [
        {
          "key": "4085",
          "doc_count": 4,
          "tops": {
            "hits": {
              "total": 4,
              "max_score": 6.1574936,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "5387",
                  "_score": 6.1574936,
                  "_source": {
                    "suggest": "Fortune Refined Sunflower Oil",
                    "title": "Fortune Refined Sunflower Oil",
                    "phonetic": "Fortune Refined Sunflower Oil",
                    "product_id": "4085",
                    "variation_id": "5387",
                    "unit": "5 LTR JAR"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "4086",
          "doc_count": 3,
          "tops": {
            "hits": {
              "total": 3,
              "max_score": 6.142435,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "5390",
                  "_score": 6.142435,
                  "_source": {
                    "suggest": "Fortune Refined Cottonseed Oil",
                    "title": "Fortune Refined Cottonseed Oil",
                    "phonetic": "Fortune Refined Cottonseed Oil",
                    "product_id": "4086",
                    "variation_id": "5390",
                    "unit": "5 LTR JAR"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "4804",
          "doc_count": 3,
          "tops": {
            "hits": {
              "total": 3,
              "max_score": 5.9258366,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "6425",
                  "_score": 5.9258366,
                  "_source": {
                    "suggest": "Fortune Refined Soyabean Oil",
                    "title": "Fortune Refined Soyabean Oil",
                    "phonetic": "Fortune Refined Soyabean Oil",
                    "product_id": "4804",
                    "variation_id": "6425",
                    "unit": "1 LTR"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "4820",
          "doc_count": 3,
          "tops": {
            "hits": {
              "total": 3,
              "max_score": 5.9258366,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "6464",
                  "_score": 5.9258366,
                  "_source": {
                    "suggest": "Fortune Rice Bran Oil",
                    "title": "Fortune Rice Bran Oil",
                    "phonetic": "Fortune Rice Bran Oil",
                    "product_id": "4820",
                    "variation_id": "6464",
                    "unit": "1 LTR"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "1014",
          "doc_count": 2,
          "tops": {
            "hits": {
              "total": 2,
              "max_score": 6.1574936,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "1324",
                  "_score": 6.1574936,
                  "_source": {
                    "suggest": "Fortune Rozana Basmati Rice",
                    "title": "Fortune Rozana Basmati Rice",
                    "phonetic": "Fortune Rozana Basmati Rice",
                    "product_id": "1014",
                    "variation_id": "1324",
                    "unit": "5 KG"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "1026",
          "doc_count": 2,
          "tops": {
            "hits": {
              "total": 2,
              "max_score": 5.6601067,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "1341",
                  "_score": 5.6601067,
                  "_source": {
                    "suggest": "Fortune Everyday Full Grain Rice",
                    "title": "Fortune Everyday Full Grain Rice",
                    "phonetic": "Fortune Everyday Full Grain Rice",
                    "product_id": "1026",
                    "variation_id": "1341",
                    "unit": "1 Kg"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "4812",
          "doc_count": 2,
          "tops": {
            "hits": {
              "total": 2,
              "max_score": 5.4391136,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "6445",
                  "_score": 5.4391136,
                  "_source": {
                    "suggest": "Fortune Kachi Ghani Mustard Oil",
                    "title": "Fortune Kachi Ghani Mustard Oil",
                    "phonetic": "Fortune Kachi Ghani Mustard Oil",
                    "product_id": "4812",
                    "variation_id": "6445",
                    "unit": "1 LTR JAR"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "4861",
          "doc_count": 2,
          "tops": {
            "hits": {
              "total": 2,
              "max_score": 7.4589143,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "6532",
                  "_score": 7.4589143,
                  "_source": {
                    "suggest": "Fortune Besan",
                    "title": "Fortune Besan",
                    "phonetic": "Fortune Besan",
                    "product_id": "4861",
                    "variation_id": "6532",
                    "unit": "1 KG"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "610",
          "doc_count": 2,
          "tops": {
            "hits": {
              "total": 2,
              "max_score": 5.9555407,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "840",
                  "_score": 5.9555407,
                  "_source": {
                    "suggest": "Fortune Soya Chunks",
                    "title": "Fortune Soya Chunks",
                    "phonetic": "Fortune Soya Chunks",
                    "product_id": "610",
                    "variation_id": "840",
                    "unit": "1 KG"
                  }
                }
              ]
            }
          }
        },
        {
          "key": "714",
          "doc_count": 2,
          "tops": {
            "hits": {
              "total": 2,
              "max_score": 6.142435,
              "hits": [
                {
                  "_index": "product_surat",
                  "_type": "surat",
                  "_id": "970",
                  "_score": 6.142435,
                  "_source": {
                    "suggest": "Fortune Vivo Blended Oil",
                    "title": "Fortune Vivo Blended Oil",
                    "phonetic": "Fortune Vivo Blended Oil",
                    "product_id": "714",
                    "variation_id": "970",
                    "unit": "1 LTR POUCH"
                  }
                }
              ]
            }
          }
        }
      ]
    }
  }
}  

в соответствии с ответом, я получаю только 25 хитов в aggregations.buckets, но я не получил другие 7 результатов в этом.
Итак, как я могу получить эти результаты, и если я хочу сделать пагинацию 5 продуктов за раз, как я могу этого достичь.

Спасибо за вашу помощь! : -)

...