Hello,
In my database I have products, each products have differents offers and offers have sales.
A sale is defined by a sale datetime and a nb (number of sales for de date)
I have to get produts and offers who have sales on a period, for each offer get the sum of sale for the period and car sort on this sales sum.
so I've defined in mapping offers.sales as nested object and for the moment i've have this query :
{
"query": {
"bool": {
"must": {
"nested": {
"path": "offers.sales",
"query": {
"range": {
"offers.sales.saleDate": {
"from": "2018-08-01"
}
}
},
"inner_hits": {}
}
}
}
},
"sort": [
{
"offers.sales.nb": {
"order": "desc",
"mode": "sum",
"nested_filter": {
"range": {
"offers.sales.saleDate": {
"gte": "2018-08-01"
}
}
}
}
}
]
}
int inner_hits I have filtered sales, but I don't know how to sum them because aggs are not able in nested query...
someone could give me a way to get my result please ?