我有以下弹性搜索doc结构,与客户类型的学生,老师,专业我想要我的搜索结果在学生,老师,专业订单,在搜索结果中所有学生的所有教师跟随所有,专业的。< / p>
{ "_index": "customer", "_type": "info", "_id": "AWC1xn90RETWF5jlQtczjt", "_version": 1, "_score": 1, "_source": { "name": "name1", "type":"student" } }
{ "_index": "customer", "_type": "info", "_id": "AWC1xnRE23TWF5jlQtczjt", "_version": 1, "_score": 1, "_source": { "name": "name4", "type":"teacher" } }
{ "_index": "customer", "_type": "info", "_id": "AWC1xnRETWF545jlQtczjt", "_version": 1, "_score": 1, "_source": { "name": "name3", "type":"professional" } }
答案 0 :(得分:1)
我会通过在索引时为每个类型分配数值来解决这个问题。 因此,student = 0,teacher = 1,professional = 2,并将其称为type_id,并按此顺序排序。
但是,如果没有这样的选项,您可以使用脚本字段
sort: [
{
_script: {
type: 'number',
script: {
lang: 'painless',
inline: 'switch(doc['type'].value){ case "student" return 0; case "teacher" return 1; case "professional" default return -1}',
},
order: 'desc',
},
}
]