【发布时间】:2019-10-11 06:28:47
【问题描述】:
我是 Elasticsearch 的新手,如果我问的查询非常简单明了,我深表歉意。
我正在使用以下学生及其教育详细信息的映射,
PUT students
{
"mappings" : {
"properties" : {
"StudentName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"Education" : {
"type" : "nested",
"properties" : {
"degreeName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"schoolName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"endDate" : {
"type" : "date"
},
"startDate" : {
"type" : "date"
}
}
}
}
}
}
我的数据集中有近 15000 名学生。 文档示例:
PUT students/_doc/2
{
"StudentName":"Student 2",
"Education": [
{
"degreeName": "MS",
"schoolName": "School Y",
"startDate": "2016-05-01",
"endDate":"2014-01-01"
},
{
"degreeName": "PhD",
"schoolName": "School X",
"startDate": "2019-01-01",
"endDate":"2017-05-01"
},
{
"degreeName": "BE",
"schoolName": "School Z",
"startDate": "2013-05-01",
"endDate":"2009-01-01"
}]
}
PUT students/_doc/3
{
"StudentName":"Student 3",
"Education": [
{
"degreeName": "BE",
"schoolName": "School P",
"startDate": "2003-01-01",
"endDate":"1999-05-01"
}]
}
我的问题是,我正在尝试做一个简单的查询来显示以“BE”为学位的学生。但我希望目前获得 BE(工程学士)学位的学生排名高于同时获得硕士和博士学位的学生。
从我的示例中,如果我查询“BE”,学生 3 的排名应该高于学生 2。我应该能够根据“endDate”属性按降序对嵌套文档进行排序,然后在“degreeName”匹配时提升排序嵌套字段的第一个元素中的“BE”。
有人能解释一下吗?我经历了嵌套查询,嵌套过滤器。我确实知道如何使用“内部命中”对嵌套字段中的元素进行排序。但是我想知道是否有任何方法可以排序然后查询以提供额外的提升。
提前致谢。
【问题讨论】:
标签: elasticsearch