diff options
author | Christopher Speller <crspeller@gmail.com> | 2018-01-29 14:17:40 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-29 14:17:40 -0800 |
commit | 961c04cae992eadb42d286d2f85f8a675bdc68c8 (patch) | |
tree | 3408f2d06f847e966c53485e2d54c692cdd037c1 /vendor/gopkg.in/olivere/elastic.v5/sort_test.go | |
parent | 8d66523ba7d9a77129844be476732ebfd5272d64 (diff) | |
download | chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.gz chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.tar.bz2 chat-961c04cae992eadb42d286d2f85f8a675bdc68c8.zip |
Upgrading server dependancies (#8154)
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/sort_test.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/sort_test.go | 52 |
1 files changed, 46 insertions, 6 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/sort_test.go b/vendor/gopkg.in/olivere/elastic.v5/sort_test.go index 54e6e1e5b..b54cbd98c 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/sort_test.go +++ b/vendor/gopkg.in/olivere/elastic.v5/sort_test.go @@ -166,7 +166,7 @@ func TestGeoDistanceSort(t *testing.T) { Order(true). Unit("km"). SortMode("min"). - GeoDistance("sloppy_arc") + GeoDistance("plane") src, err := builder.Source() if err != nil { t.Fatal(err) @@ -176,7 +176,7 @@ func TestGeoDistanceSort(t *testing.T) { t.Fatalf("marshaling to JSON failed: %v", err) } got := string(data) - expected := `{"_geo_distance":{"distance_type":"sloppy_arc","mode":"min","order":"asc","pin.location":[{"lat":-70,"lon":40}],"unit":"km"}}` + expected := `{"_geo_distance":{"distance_type":"plane","mode":"min","order":"asc","pin.location":[{"lat":-70,"lon":40}],"unit":"km"}}` if got != expected { t.Errorf("expected\n%s\n,got:\n%s", expected, got) } @@ -187,7 +187,7 @@ func TestGeoDistanceSortOrderDesc(t *testing.T) { Point(-70, 40). Unit("km"). SortMode("min"). - GeoDistance("sloppy_arc"). + GeoDistance("arc"). Desc() src, err := builder.Source() if err != nil { @@ -198,7 +198,7 @@ func TestGeoDistanceSortOrderDesc(t *testing.T) { t.Fatalf("marshaling to JSON failed: %v", err) } got := string(data) - expected := `{"_geo_distance":{"distance_type":"sloppy_arc","mode":"min","order":"desc","pin.location":[{"lat":-70,"lon":40}],"unit":"km"}}` + expected := `{"_geo_distance":{"distance_type":"arc","mode":"min","order":"desc","pin.location":[{"lat":-70,"lon":40}],"unit":"km"}}` if got != expected { t.Errorf("expected\n%s\n,got:\n%s", expected, got) } @@ -214,7 +214,7 @@ func TestScriptSort(t *testing.T) { t.Fatalf("marshaling to JSON failed: %v", err) } got := string(data) - expected := `{"_script":{"order":"asc","script":{"inline":"doc['field_name'].value * factor","params":{"factor":1.1}},"type":"number"}}` + expected := `{"_script":{"order":"asc","script":{"params":{"factor":1.1},"source":"doc['field_name'].value * factor"},"type":"number"}}` if got != expected { t.Errorf("expected\n%s\n,got:\n%s", expected, got) } @@ -231,7 +231,47 @@ func TestScriptSortOrderDesc(t *testing.T) { t.Fatalf("marshaling to JSON failed: %v", err) } got := string(data) - expected := `{"_script":{"order":"desc","script":{"inline":"doc['field_name'].value * factor","params":{"factor":1.1}},"type":"number"}}` + expected := `{"_script":{"order":"desc","script":{"params":{"factor":1.1},"source":"doc['field_name'].value * factor"},"type":"number"}}` + if got != expected { + t.Errorf("expected\n%s\n,got:\n%s", expected, got) + } +} + +func TestNestedSort(t *testing.T) { + builder := NewNestedSort("offer"). + Filter(NewTermQuery("offer.color", "blue")) + src, err := builder.Source() + if err != nil { + t.Fatal(err) + } + data, err := json.Marshal(src) + if err != nil { + t.Fatalf("marshaling to JSON failed: %v", err) + } + got := string(data) + expected := `{"filter":{"term":{"offer.color":"blue"}},"path":"offer"}` + if got != expected { + t.Errorf("expected\n%s\n,got:\n%s", expected, got) + } +} + +func TestFieldSortWithNestedSort(t *testing.T) { + builder := NewFieldSort("offer.price"). + Asc(). + SortMode("avg"). + NestedSort( + NewNestedSort("offer").Filter(NewTermQuery("offer.color", "blue")), + ) + src, err := builder.Source() + if err != nil { + t.Fatal(err) + } + data, err := json.Marshal(src) + if err != nil { + t.Fatalf("marshaling to JSON failed: %v", err) + } + got := string(data) + expected := `{"offer.price":{"mode":"avg","nested":{"filter":{"term":{"offer.color":"blue"}},"path":"offer"},"order":"asc"}}` if got != expected { t.Errorf("expected\n%s\n,got:\n%s", expected, got) } |