I cannot use FieldSortBuilder to sort by multiple fields and do the exception condition. So I am wondering can we use painless to do it?
Below is data model.
{ "name" : "string",
"email" : "string",
"schoolNumber" : "number",
"startTime" : "number",
"endTime" : "number",
}
Examples:
{ "name" : "Micheal",
"email" : "mi@gmail.com",
"schoolNumber": 1,
"startTime" : 123,
}
{ "name" : "Racheal",
"email" : "ra@gmail.com",
"schoolNumber": 1,
"startTime" : 456,
"endTime" : 789,
}
{ "name" : "Racheal",
"email" : "ra@gmail.com",
"schoolNumber": 2,
"startTime" : 987,
}
Only endTime is optional. I want to sort all the profiles in startTime by asc, these profiles only have startTime, endTime should inactive and they should have the same schoolNumber.
public static final String SORT_SCRIPT =
"if (doc['endTime.raw'].value == null) {
//sort by startTime which have same schoolNumber
} else {
//sort by endTime which have same schoolNumber
}";
Another solution: I want to use FieldSortBuilder to set nestedFiler to exclude the endTime
sortBuilder.setNestedFilter(new TermQueryBuilder(LICENSE_ASSIGNMENT_ACTIVATION_TIME_PROPERTY, value:???)
But I don't know how to set value. I have tried with "null" "false" "ScoreMode.None". All failed.