Extend "sort on nested text fields" feature with possibility to add nested filter
Change existing nested sorting signature
From:
nested(path, field, mode)
To:
nested(path, field, mode, nested_filter) - (filter argument may be an optional argument to maintain backwards compatibility)
to allow user specify filter that the inner objects inside the nested path should match with in order for its field values to be taken into account by sorting (sounds complex, but this is an exact definition in elasticsearch docs)
Example use case which is enabled by this feature
Below is the data model where we need to sort based on the AliasName where AliasNameTypeID= "osdu:reference-data--AliasNameType:UWI:"
{
"data":
"NameAliases": [
{
"AliasName": "714100044935",
"TerminationDateTime": "2020-02-13T09:13:15.55+0000",
"AliasNameTypeID": "osdu:reference-data--AliasNameType:UWI:",
"EffectiveDateTime": "2020-02-13T09:13:15.55+0000",
"DefinitionOrganisationID": null
}
]
}
Proposed syntax for new argument
The same syntax as 'query' top level endpoint argument. Alternatively, raw elasticsearch syntax for filter can be used.
Example request that will accomplish desired functionality after this implementation:
{
"kind": "{{data-partition-id}}:*:*:*",
"sort": {
"field": [
"nested(data.NameAliases, AliasName, min, (AliasNameTypeID:\"osdu:reference-data--AliasNameType:UWI:\"))"
],
"order": [
"ASC"
]
}
}
Scope of required work
Changes only in Search Service, passing new argument from API layer to SortParserUtil that has to be modified. https://community.opengroup.org/osdu/platform/system/search-service/-/blob/master/search-core/src/main/java/org/opengroup/osdu/search/util/SortParserUtil.java#L118
This is originally requested as https://osdu-community.ideas.aha.io/ideas/IDEA-I-66