Hi there;
I'm trying to query three different indexes at a time, one of them have two mappings, as follows:
price: {
type: 'float'
},
offer_price: {
type: 'float'
}
The next one have only one important mapping for prices:
price: {
type: 'float'
}
And the last one have no prices mapped. when I query elasticsearch for the three indexes at a time the results are properly returned and filtered. However I would like to sort the results the following way: If there is an "offer_price" present take this value, else if there is a "price" present take this value, otherwise return 0. I'm trying to use the following painless script to that purpose:
_script: {
type: 'number',
script: {
lang: 'painless',
source:
"if(!doc['offer_price'].empty && doc['offer_price'].value != 0) { return doc['offer_price'].value; } else { if(!doc['price'].empty) { return doc['price'].value; } else { return 0; }}"
},
order: "asc" //or "desc" (this works fine for the returned docs)
}
When running the query only documents with the "offer_price" field mapped are returned, documents from the two other indexes are missing in the return set. I tried with a ternary operator with only one statement with no luck. Can anyone point me in the right direction please?
Thanks in advance.
Szz.
EDIT: Tried with:
_script: {
type: 'number',
script: {
lang: 'painless',
source:
"if(doc['offer_price'] != null && doc['offer_price'].value != 0) { return doc['offer_price'].value; } else { if(doc['price'] != null) { return doc['price'].value; } else { return 0; }}"
},
order: "asc"/"desc"
}
With no luck neither.
P.D: using elastic search 7.2.0