TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Bidzina Goginashvili
NA
206
26.5k
ElasticSearch paging sorting aggregation
Aug 5 2019 4:43 PM
.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)))));
I need to have pagination here plus sorting on parent aggregation and sub aggregation but i dont know what to do pls help me to change this original...
Reply
Answers (
1
)
token based authentication in web api .
Creating .dat file using binary writer