Reputation: 369
I would like to sort the result set on the basis of the minimum value of "priceWithPartialDiscount", which is a field inside a nested field.
Consider the nested field:
"children": [
{
"partialDiscountPercent": 0.0,
"productId": 497071,
"price": 200.0,
"priceWithPartialDiscount": 200.0,
"partialDiscountAmount": 0.0
},
{
"partialDiscountPercent": 0.0,
"productId": 497072,
"price": 100.0,
"priceWithPartialDiscount": 100.0,
"partialDiscountAmount": 0.0
}
],
I wrote the code for sort:
"sort":[{
"children.priceWithPartialDiscount":{
"missing":"_last",
"mode":"min",
"nested":{
"filter":{
"nested":{
"path":"children",
"query":{
"range":{
"children.price":{
"gte":0.0
}
}
}
}
},
"path":"children"
},
"order":"asc"
}
}]
, and I expect
"sort": [100.0]
But surprisingly I see:
"sort": [200.0]
Did I make a mistake?
Upvotes: 1
Views: 418
Reputation: 16915
Remove the 2nd level nested-ness inside of the filter
because the path
is already defined in the parent's nested context:
{
"sort": [
{
"children.priceWithPartialDiscount": {
"missing":"_last",
"mode": "min",
"nested": {
"filter": {
"range": {
"children.price": {
"gte": 0
}
}
},
"path": "children"
},
"order": "asc"
}
}
]
}
I think that 2nd level nested query was messing up your sort values in a non-obvious way.
Upvotes: 1