I have this piece of code that I need to convert into spring-data-elastic-search.
{
"query": {
"match_all": {}
},
"size": 10,
"from": 0,
"sort": [
{
"program.title.descriptions.value.keyword": {
"order": "asc",
"nested": {
"path": "program.title.descriptions",
"filter": {
"match": {
"program.title.descriptions.length": "LONG"
}
}
}
}
}
]
}
I have tried up to this,
SortBuilder sb = SortBuilders.fieldSort(sortBy).order(sortOrder).setNestedSort(new NestedSortBuilder(nestedPath))
but I don't know how to add the "filter" part into the SortBuilder. If I try the below,
QueryBuilder matchFirst = QueryBuilders.boolQuery().filter(QueryBuilders.matchQuery("program.title.descriptions.length", "LONG"));
sb = SortBuilders.fieldSort(sortBy).order(sortOrder).setNestedSort(new NestedSortBuilder(nestedPath)).setNestedFilter(matchFirst);
it would say
java.lang.IllegalArgumentException: Setting both nested_path/nested_filter and nested not allowed
at org.elasticsearch.search.sort.FieldSortBuilder.setNestedFilter(FieldSortBuilder.java:213)
Any ideas will be much appreciated.