21
21
package elasticsearch_test
22
22
23
23
import (
24
+ "bytes"
24
25
"context"
25
26
"crypto/tls"
26
27
"encoding/json"
@@ -29,6 +30,7 @@ import (
29
30
"github.com/elastic/go-elasticsearch/v8/typedapi/indices/create"
30
31
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
31
32
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/refresh"
33
+ "github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
32
34
"log"
33
35
"net"
34
36
"net/http"
@@ -495,4 +497,26 @@ func TestTypedClient(t *testing.T) {
495
497
t .Fatalf ("unexpected string in Query.Term.Value, expected kimchy, got: %s" , searchRequest .Query .Term ["user.id" ].Value .(string ))
496
498
}
497
499
})
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
+ })
498
522
}
0 commit comments