I've been trying for days to know how to sort based on multiple fields with Go olivere/elastic. I'm trying to translate this into Go
{
"sort" : [
"name",
{ "age" : "desc" },
],
}
I've tried to use the NewFieldSort() and give some SortBy() in the Search Service. It works fine with one SortBy() but won't work with two SortBy(). It returns Error 400 (Bad Request): all shards failed [type=search_phase_execution_exception]
Here's my code
sortQuery1 := elastic.NewFieldSort("name")
sortQuery2 := elastic.NewFieldSort("age").Desc()
searchService := esclient.Search().
Index("students").
SortBy(sortQuery1).
SortBy(sortQuery2)
searchResult, err := searchService.Do(ctx)
Do you guys have any suggestions on what to try? Thanks in advance!