Elastic search pagination on top hits

Hi,
I am looking for a way to paginate my results under "products" aggregation following is my query.

 {
      "size": 0,
      "aggs": {
          "sub_category": {
              "terms": {
                  "size": 10000,
                  "field": "cat_name.keyword"
              },
              "aggs": {
                  "product": {
                      "cardinality": {
                          "field": "product_id"
                      }
                  }
              }
          },
          "by_color": {
              "terms": {
                  "field": "color_title.keyword",
                  "size": 10000
              },
              "aggs": {
                  "product": {
                      "cardinality": {
                          "field": "product_id"
                      }
                  }
              }
          },
          "by_brand": {
              "terms": {
                  "field": "brand_name.keyword",
                  "size": 10000
              },
              "aggs": {
                  "product": {
                      "cardinality": {
                          "field": "product_id"
                      }
                  }
              }
          },
          "max_price_range": {
              "max": {
                  "field": "item_price"
              }
          },
          "min_price_range": {
              "min": {
                  "field": "item_price"
              }
          },
          "products": {
              "terms": {
                  "field": "product_id",
                  "size": 20
              },
              "aggs": {
                  "data": {
                      "top_hits": {
                          "size": 1,
                          "_source": {
                              "includes": []
                          }
                      }
                  }
              }
          }
      },
      "query": {
          "bool": {
              "filter": {
                  "script": {
                      "script": {
                          "source": "doc['image_src.keyword'].size()!=0",
                          "lang": "painless"
                      }
                  }
              }
          }
      }
  }

In my query I am doing aggregation and found total count base on color, brand etc. In a same query I am getting products as well using top hits. I like to paginate my product data but pagination should not affect total count of color, brand and etc.

I there any way to do that.

Thanks in advance

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.