goopensearch

How to specify sort order in search request


I am creating below request in opensearch go client. I am able to provide sort field, but I cannot see any option or way to provide sort order - ascending / descending. I want search request to sort on a particular field in descending order.

"github.com/opensearch-project/opensearch-go"
"github.com/opensearch-project/opensearch-go/opensearchapi"

req := opensearchapi.SearchRequest{
    Index:  []string{index},
    Body:   dbQuery,
    From:   &from,
    Size:   &size,
    Pretty: true,
    Sort:   []string{sortField},
}

response, err := req.Do(ctx, client)
if err != nil {
    return nil, err
}

defer response.Body.Close()

Solution

  • Sort:   []string{"field1:desc", "field2:asc",...}