假设我有一个这样映射的文档:
{
"corp" : {
"mappings" : {
"staff" : {
"properties" : {
"created" : {
"type" : "date",
"format" : "dateOptionalTime"
},
"name" : {
"type" : "string"
},
"public" : {
"type" : "boolean"
},
"salary" : {
"type" : "long"
}
}
}
}
}
}
像这样的数据集:
[{"name": "John", "salary": 100000, "public": true, "created": "<datestamp>"},
{"name": "Bob", "salary": 80000, "public": false, "created": "<datestamp>"},
{"name": "Wendy", "salary": 110000, "public": true, "created": "<datestamp>"},
{"name": "Joan", "salary": 210000, "public": false, "created": "<datestamp>"}]
我想构造一个排序,使我们仅在
public=true
处按薪水排序,然后通过created
字段对其余项目进行排序。最终结果应为:went
created
日期)created
日期)这可能吗?
最佳答案
应该这样做:
GET /corp/staff/_search
{
"sort": [
{
"public": {
"order": "desc"
}
},
{
"salary": {
"order": "asc"
}
},
{
"created": {
"order": "asc"
}
}
]
}
关于sorting - Elasticsearch:按条件匹配的字段对某些项目进行排序,其他按条件进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30362582/