经过研究,我发现了如何像这样在Elasticsearch上使用无痛脚本自定义排序
{
'_script': {
'type': 'number',
'script': {
'lang': 'painless',
'source': 'int sortOrder = 0; if (doc[\'inspectionRatingTranslated.keyword\'].value == \'S\') {sortOrder = 1} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'6\') {sortOrder = 2} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'5.5\') {sortOrder = 3} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'5\') {sortOrder = 4} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'4.5\') {sortOrder = 5} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'4\') {sortOrder = 6} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'3.5\') {sortOrder = 7} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'3\') {sortOrder = 8} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'2.5\') {sortOrder = 9} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'2\') {sortOrder = 10} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'1.5\') {sortOrder = 11} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'1\') {sortOrder = 12} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'RA\') {sortOrder = 13} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'R\') {sortOrder = 14} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'X\') {sortOrder = 15} else if (doc[\'inspectionRatingTranslated.keyword\'].value == \'XX\') {sortOrder = 16} sortOrder;'
},
'order': 'asc'
}
}
但是我的公司仍然使用ES 2.4,所以我不能使用轻松的语言。任何人都告诉我如何在表情,表情或任何内置方式上实现此代码 ES 2.4是否支持脚本?