Open nagyt234 opened 6 years ago
Any chance for this feature?
All PRs are welcome.
This has actually been implemented. One caveat: you can not sort on a script field by providing its name. You actually need to provide the script. Here's the example from the official docs:
{
"query": {
"term": {
"sold": "true"
}
},
"sort": {
"_script": {
"type": "number",
"script": {
"lang": "painless",
"source": "doc['theatre'].value.length() * params.factor",
"params": {
"factor": 1.1
}
},
"order": "asc"
}
}
}
Let's rewrite this using yii2-elasticsearch.
$query->where(['sold' => 'true'])->orderBy(['_script' => [
'lang' => 'painless'
'source' => "doc['theatre'].value.length() * params.factor",
'params' => [
'factor' => 1.1
]
]]);
Note how the value for the _script
key is an array, not a string.
This needs to be put into the docs.
It would be good to have the possibility to use script sorting of ElasticSearch. E.g.:
It is possible to use script field:
It would be the best if we could use such a script field in the orderBy method.