Hello everyone, I am a newbie to Elasticsearch and apologies if the query i am asking is very simple and straightforward.
I am using following mapping of students with their education details,
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"
}
}
}
}
}
}
I have close to 15000 students in my data set.
Example of document:
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"
}]
}
My question is, I am trying to do a simple query to show students who have "BE" as their degree. But I want students who have current degree as BE (Bachelor of Engineering) to be ranked higher than students who also did Master's and PhD.
From my examples, if I query for "BE" student 3 should be ranked higher than student 2. I should be able to sort my nested documents in descending order based on "endDate" property and then boost if "degreeName" matches "BE" in the first element of sorted nested field.
Could anyone please throw some light on this? I have gone through nested query, nested filter. I do know how to sort elements in nested field using "Inner hits". But I would like to know if there is any way to sort and then query to give extra boost.
Thanks in advance.