2121package elasticsearch_test
2222
2323import (
24+ "bytes"
2425 "context"
2526 "crypto/tls"
2627 "encoding/json"
@@ -29,6 +30,7 @@ import (
2930 "github.com/elastic/go-elasticsearch/v8/typedapi/indices/create"
3031 "github.com/elastic/go-elasticsearch/v8/typedapi/types"
3132 "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/refresh"
33+ "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
3234 "log"
3335 "net"
3436 "net/http"
@@ -495,4 +497,26 @@ func TestTypedClient(t *testing.T) {
495497 t .Fatalf ("unexpected string in Query.Term.Value, expected kimchy, got: %s" , searchRequest .Query .Term ["user.id" ].Value .(string ))
496498 }
497499 })
500+
501+ t .Run ("Sort serialisation" , func (t * testing.T ) {
502+ qry := search .NewRequestBuilder ().Sort (
503+ types .NewSortBuilder ().Sort (
504+ []types.SortCombinations {
505+ types .NewSortCombinationsBuilder ().
506+ Field ("@timestamp" ).
507+ SortOptions (types .NewSortOptionsBuilder ().
508+ SortOptions (map [types.Field ]* types.FieldSortBuilder {
509+ "@timestamp" : types .NewFieldSortBuilder ().Format ("strict_date_optional_time_nanos" ).Order (sortorder .Asc ),
510+ })).Build (),
511+ })).Build ()
512+
513+ data , err := json .Marshal (qry )
514+ if err != nil {
515+ t .Fatal (err )
516+ }
517+
518+ if bytes .Compare (data , []byte (`{"sort":[{"@timestamp":{"format":"strict_date_optional_time_nanos","order":"asc"}}]}` )) != 0 {
519+ t .Fatalf ("invalid sort serialisation, got: %s" , data )
520+ }
521+ })
498522}
0 commit comments