I have a query which contains a script for supporting sorting operation on an index,
The script requires few parameters, which I'm currently constructing in code
These parameters are being fetched from another index called currency_rates
I wanted to know if there is a way, I could do a subquery in the scripting to get the param values from it?
Here's the query I'm using -
GET products/_search
{
"query": {
"function_score": {
"query": {
"match_all": {}
},
"functions": [{
"script_score": {
"script": {
"params": {
"USD": 1,
"SGD": 0.72,
"MYR": 0.24,
"INR": 0.014,
"EUR": 1.12
},
"source": "doc['price'].value * params[doc['currency.keyword'].value]"
}
}
}]
}
},
"sort": [
{
"_score": {
"order": "desc"
}
}
]
}
The part of the query which I currently need to construct -
"params": {
"USD": 1,
"SGD": 0.72,
"MYR": 0.24,
"INR": 0.014,
"EUR": 1.12
}
The source of these param values is an index called currency_rates
-
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 1,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "curency_rates",
"_type" : "_doc",
"_id" : "1",
"_score" : 1.0,
"_source" : {
"id" : 1,
"USD" : 1,
"SGD" : 0.72,
"MYR" : 0.24,
"INR" : 0.014,
"EUR" : 1.12
}
}
]
}
}
I use the following query to fetch data from currency_rates -
GET /curency_rates/_search
{
"query": {
"match_all": {}
}
}