Skip to content

Commit 4c46e66

Browse files
authored
[Backport 8.5] [Typed API] Simplification and builder removal (#546)
* API: Update typed API for Elasticsearch v8.5.0 (a8bf13e) * Fix integration tests following API change
1 parent 45f2b97 commit 4c46e66

File tree

2,412 files changed

+17219
-95745
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,412 files changed

+17219
-95745
lines changed

elasticsearch_integration_test.go

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"fmt"
2929
"github.com/elastic/go-elasticsearch/v8/typedapi/core/search"
3030
"github.com/elastic/go-elasticsearch/v8/typedapi/indices/create"
31+
"github.com/elastic/go-elasticsearch/v8/typedapi/some"
3132
"github.com/elastic/go-elasticsearch/v8/typedapi/types"
3233
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/refresh"
3334
"github.com/elastic/go-elasticsearch/v8/typedapi/types/enums/sortorder"
@@ -339,9 +340,9 @@ func TestTypedClient(t *testing.T) {
339340
res, err := es.Indices.Create(indexName).
340341
Request(&create.Request{
341342
Mappings: &types.TypeMapping{
342-
Properties: map[types.PropertyName]types.Property{
343-
"price": types.NewIntegerNumberPropertyBuilder().Build(),
344-
"name": types.NewKeywordPropertyBuilder().Build(),
343+
Properties: map[string]types.Property{
344+
"price": types.NewIntegerNumberProperty(),
345+
"name": types.NewKeywordProperty(),
345346
},
346347
},
347348
}).
@@ -401,8 +402,8 @@ func TestTypedClient(t *testing.T) {
401402
res, err := es.Search().
402403
Index(indexName).
403404
Request(&search.Request{
404-
Query: &types.QueryContainer{
405-
Match: map[types.Field]types.MatchQuery{
405+
Query: &types.Query{
406+
Match: map[string]types.MatchQuery{
406407
"name": {Query: "Foo"},
407408
},
408409
},
@@ -446,18 +447,15 @@ func TestTypedClient(t *testing.T) {
446447

447448
pa := PriceAggregation{}
448449

449-
size := 0
450-
field := types.Field("price")
451-
452450
totalPricesAgg, err := es.Search().
453451
Index(indexName).
454452
Request(
455453
&search.Request{
456-
Size: &size,
457-
Aggregations: map[string]types.AggregationContainer{
454+
Size: some.Int(0),
455+
Aggregations: map[string]types.Aggregations{
458456
"total_prices": {
459457
Sum: &types.SumAggregation{
460-
Field: &field,
458+
Field: some.String("price"),
461459
},
462460
},
463461
},
@@ -479,7 +477,7 @@ func TestTypedClient(t *testing.T) {
479477
})
480478

481479
t.Run("Term query from JSON", func(t *testing.T) {
482-
searchRequest, err := search.NewRequestBuilder().FromJSON(`{
480+
searchRequest, err := search.NewRequest().FromJSON(`{
483481
"query": {
484482
"term": {
485483
"user.id": {
@@ -499,16 +497,13 @@ func TestTypedClient(t *testing.T) {
499497
})
500498

501499
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()
500+
qry := search.Request{
501+
Sort: []types.SortCombinations{
502+
types.SortOptions{SortOptions: map[string]types.FieldSort{
503+
"@timestamp": {Format: some.String("strict_date_optional_time_nanos"), Order: &sortorder.Asc},
504+
}},
505+
},
506+
}
512507

513508
data, err := json.Marshal(qry)
514509
if err != nil {

typedapi/api._.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typedapi/asyncsearch/delete/delete.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typedapi/asyncsearch/get/get.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

typedapi/asyncsearch/status/status.go

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)