we have a situation where treatment has a price and hospital may or may not want to display it.
so there is a price
field PLUS a lp_low_priority
field.
value of lp_low_priority
is 1 (true) when price
is not set(price is_null).
Vendor doc is saved with its nested products.
when user searches for treatment he get list of hospitals with minimum price of the treatment.
now the sort works fine.
BUT i want the hospital with that treatment with the lp_low_priority
= 1
to come at last.
{
"properties":{
.....
"treatments":{
"properties":{
"child_of":{
"type":"integer"
},
"hospital_id":{
"type":"integer"
},
"id":{
"type":"integer"
},
"keywords":{
"type":"string"
},
"procedure_count": {
"type": "long"
},
"status":{
"type":"string",
"index":"not_analyzed"
},
"treatment_id":{
"type":"integer"
},
"treatment_name":{
"type":"string"
},
"treatment_price":{
"type":"integer"
},
"treatment_slug":{
"type":"string",
"index":"not_analyzed"
},
"treatment_status":{
"type":"string",
"index":"not_analyzed"
},
"low_priority": {
"type": "integer"
},
"lowest_price": {
"type": "integer"
},
"highest_price": {
"type": "integer"
},
"lp_low_priority": {
"type": "integer"
},
"hp_low_priority": {
"type": "integer"
}
}
}
}
}
the code to search it is like
{
"sort": [
{
"treatments.lowest_price": {
"nested_filter": {
"term": {
"treatments.treatment_slug": "heart-surgery"
}
},
"mode": "avg",
"order": "asc"
}
},
{
"treatments.lp_low_priority": {
"order": "asc",
"nested_filter": {
"term": {
"treatments.treatment_slug": "heart-surgery"
}
},
"mode": "max"
}
}
],
"query": {
"filtered": {
"filter": [
{
"term": {
"treatments.treatment_slug": "heart-surgery"
}
},
{
"term": {
"treatments.status": "active"
}
},
{
"term": {
"treatments.treatment_status": "active"
}
},
{
"term": {
"hospital_status": "active"
}
},
{
"terms": {
"location.country": [
"India"
]
}
}
]
}
}
}
the result is way too weird.
if I only use
{
"sort": [
{
"treatments.lowest_price": {
"nested_filter": {
"term": {
"treatments.treatment_slug": "heart-surgery"
}
},
"mode": "avg",
"order": "asc"
}
}
The sorting is in order but then you see the `lp_low_priority` come first in order, which is OK(but not the requirement).
can i use multiple sorts?