Pagination + Sorting + Aggregaition? Has Anyone done this magic yeat ? PLS HELP

Please it will be helpfull if you give me a script...

{
"onoff-products-tests-main-test" : {
"mappings" : {
"properties" : {
"Categories" : {
"type" : "nested",
"properties" : {
"Id" : {
"type" : "integer"
}
}
},
"FullDescription" : {
"type" : "text"
},
"InStorage" : {
"type" : "boolean"
},
"ManufacturerPartNumber" : {
"type" : "text"
},
"Manufacturers" : {
"type" : "nested",
"properties" : {
"Id" : {
"type" : "integer"
}
}
},
"ModelName" : {
"type" : "keyword"
},
"Name" : {
"type" : "text"
},
"Options" : {
"type" : "nested",
"properties" : {
"AllowFiltering" : {
"type" : "boolean"
},
"Id" : {
"type" : "integer"
}
}
},
"ParentBaseProductId" : {
"type" : "long"
},
"Price" : {
"type" : "double"
},
"ShortDescription" : {
"type" : "text"
},
"Sku" : {
"type" : "text"
},
"VendorId" : {
"type" : "integer"
},
"categories" : {
"properties" : {
"id" : {
"type" : "long"
}
}
},
"customProperties" : {
"type" : "object"
},
"fullDescription" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"id" : {
"type" : "long"
},
"inStorage" : {
"type" : "boolean"
},
"manufacturers" : {
"properties" : {
"id" : {
"type" : "long"
}
}
},
"modelName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"options" : {
"properties" : {
"allowFiltering" : {
"type" : "boolean"
},
"id" : {
"type" : "long"
}
}
},
"parentBaseProductId" : {
"type" : "long"
},
"price" : {
"type" : "float"
},
"shortDescription" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"sku" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"vendorId" : {
"type" : "long"
}
}
}
}
}

THIS IS MY MAPNG

THIS IS WHAT I AM TRYING TO DO
var Response = searchDescriptor
.Index("onoff-products-tests-main")
.RequestCache(true)
.From(0)
.Size(15)
.Query(q =>
{
QueryContainer container = +q.Terms(c => c
.Field("categories.id")
.Terms(categoryIds));

            if (manufacturerIds?.Any() == true)
            {
                container = container && +q.Terms(ma => ma
                    .Field("manufacturers.id")
                         .Terms(manufacturerIds));
            }
            if (filteredSpecs?.Any() == true)
            {
                container = container && +q.Terms(ma => ma
                    .Field("options.id")
                         .Terms(filteredSpecs));
            }
            if (vendorIds?.Any() == true)
            {
                container = container && +q.Terms(c => c
                     .Field("vendor.id")
                         .Terms(vendorIds));
            }
            if (inStorage == true)
            {
                container = container && +q.Term(c => c
                    .Field("inStorage")
                         .Value(true));
            }
            if (priceMax.HasValue || priceMin.HasValue)
            {
                container = container && +q.TermRange(x => x
                    .Field("price")
                        .GreaterThan("0")
                                .LessThan("20"));
            }

            return container;
        }).Aggregations(agg => agg
                   .Terms("products_aggregation",
                       x => x.Field("modelName.keyword")
                           .Include(partition,partition+15)
                            .Size(15)
          .Aggregations(agg2 => agg2
              .TopHits("sameModeledProducts_aggregation",
                  s => s.Sort((ss) =>
                  {
                      switch (orderBy)
                      {
                          case ProductSortingEnum.NameAsc:
                              return ss.Ascending(ff => ff.Name);
                          case ProductSortingEnum.NameDesc:
                              return ss.Descending(ff => ff.Name);
                          case ProductSortingEnum.PriceAsc:
                              return ss.Ascending(ff => ff.Price);
                          case ProductSortingEnum.PriceDesc:
                              return ss.Descending(ff => ff.Price);
                          case ProductSortingEnum.MostViewedDesc:
                              return ss.Descending(ff => ff.Price);
                          default:
                              return ss.Descending(ff => ff.Price);
                      }
                  }).Source(ss => ss.Includes(i => i.Field(f => f.Id)))
                          .Size(100)))));

BUT I CANNT PAGINATE AND SORT ALL OVER THE RECORDS PLEASEEE HELP...

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