Skip to content

Commit 8a5741c

Browse files
Update the documentation to remove the builder API (#550) (#551)
Co-authored-by: Laurent Saint-Félix <laurent.saintfelix@elastic.co>
1 parent 349ff35 commit 8a5741c

File tree

10 files changed

+32
-73
lines changed

10 files changed

+32
-73
lines changed

.doc/installation.asciidoc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[[installation]]
22
== Installation
33

4-
To install the 7.x version of the client, add the package to your `go.mod` file:
4+
To install the 8.x version of the client, add the package to your `go.mod` file:
55

66
[source,text]
77
------------------------------------
8-
require github.com/elastic/go-elasticsearch/v7 7.16
8+
require github.com/elastic/go-elasticsearch/v8 8.5
99
------------------------------------
1010

1111
Or, clone the repository:
1212

1313
[source,text]
1414
------------------------------------
15-
git clone --branch 7.16 https://github.com/elastic/go-elasticsearch.git $GOPATH/src/github
15+
git clone --branch 8.5 https://github.com/elastic/go-elasticsearch.git $GOPATH/src/github
1616
------------------------------------
1717

1818
To install another version, modify the path or the branch name accordingly. The

.doc/typedapi/conventions/endpoints.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
All the available endpoints are generated in separate packages and assembled in the client. The `core` namespace is duplicated at the root of the client for convenient access.
55

6-
Each endpoint follows a factory pattern which returns a pointer to a new instance each time. This leads to a builder pattern allowing to directly chain the options before running your query.
6+
Each endpoint follows a factory pattern which returns a pointer to a new instance each time.
77

88
[source,go]
99
-----

.doc/typedapi/conventions/naming.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
Whenever appropriate, names may be suffixed with an underscore:
55

6-
* To avoid collision with protected keywords (`range, `if`, `type`, and so on).
6+
* To avoid collision with protected keywords (`range`, `if`, `type`, and so on).
77
* To reflect the presence of a leading underscore in the API like `\_index` vs `Index_` or `\_source` vs `Source_`.

.doc/typedapi/conventions/requests.asciidoc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,11 @@
44
Requests are modeled around structures that follows as closely as possible the {es} API and uses the standard `json/encoding` for serialization.
55
Corresponding request can be found withing the same package as its endpoint and comes with a Builder that allows you to deep dive into the API by following the types.
66

7-
The builder is particularly useful around pointer fields and is embeddable within a standard struct declaration, such that these two declarations give you the same result:
8-
97
[source,go]
108
------------------------------------
11-
types.QueryContainer{
12-
Term: map[types.Field]types.TermQuery{
9+
types.Query{
10+
Term: map[string]types.TermQuery{
1311
"name": {Value: "Foo"},
1412
},
1513
}
16-
types.QueryContainer{
17-
Term: map[types.Field]types.TermQuery{
18-
"name": types.NewTermQueryBuilder().Value(types.NewFieldValueBuilder().String("Foo")).Build(),
19-
},
20-
}
2114
------------------------------------

.doc/typedapi/conventions/structure.asciidoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ The Typed client lives in the `typedapi` package within the `go-elasticsearch` r
55

66
The entire client is summed in an index at the root of the package for convenient access after instantiation.
77

8-
Each endpoint resides in its own package within `typedapi` and contains the client for this endpoint, the `Request` struct along with its builder, if applicable.
8+
Each endpoint resides in its own package within `typedapi` and contains the client for this endpoint, and the `Request` struct if applicable.
99

10-
The requests are based on a collection of structures generated from the https://github.com/elastic/elasticsearch-specification[elasticsearch-specification] repository and gathered in a `types` package within `typedapi`.
11-
Each type comes with a fluent builder for convenient creation and discoverability.
10+
The requests are based on a collection of structures generated from the https://github.com/elastic/elasticsearch-specification[elasticsearch-specification] repository and gathered in a `types` package within `typedapi`.

.doc/typedapi/conventions/types.asciidoc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
==== Types
33

44
Requests and responses are relying on a collection of structures generated from the https://github.com/elastic/elasticsearch-specification[elasticsearch-specification] in the `types` package.
5-
Each type comes with json tags and a builder.
5+
Each type comes with json tags.
66

77
==== Enums
88

@@ -19,5 +19,4 @@ refresh.Waitfor => "wait_for"
1919

2020
==== Unions
2121

22-
To capture the expressiveness of the API union fields are represented by a type alias to an interface.
23-
Each type alias comes with a builder that lists the possible types for the underlying value.
22+
To capture the expressiveness of the API union fields are represented by a type alias to an interface.

.doc/typedapi/examples/aggregations.asciidoc

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ Given documents with a `price` field, we run a sum aggregation on `index_name`:
55
[source,go]
66
-----
77
totalPricesAgg, err := es.Search().
8-
Index("index_name"). // <1>
9-
Request(
10-
search.NewRequestBuilder().
11-
Size(0). // <2>
12-
Aggregations(
13-
map[string]*types.AggregationContainerBuilder{
14-
"total_prices": types.NewAggregationContainerBuilder(). // <3>
15-
Sum(types.NewSumAggregationBuilder().Field("price")), // <4>
16-
}).
17-
Build(),
18-
).Do(context.Background())
8+
Index("index_name"). // <1>
9+
Request(
10+
&search.Request{
11+
Size: some.Int(0), // <2>
12+
Aggregations: map[string]types.Aggregations{
13+
"total_prices": { // <3>
14+
Sum: &types.SumAggregation{
15+
Field: some.String("price"), // <4>
16+
},
17+
},
18+
},
19+
},
20+
).Do(context.Background())
1921
-----
2022
<1> Specifies the index name.
2123
<2> Sets the size to 0 to retrieve only the result of the aggregation.
2224
<3> Specifies the field name on which the sum aggregation runs.
23-
<4> The `SumAggregation` is part of the `AggregationContainer` map.
25+
<4> The `SumAggregation` is part of the `Aggregations` map.

.doc/typedapi/examples/indices.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ Notice how using the builder for the `IntegerNumberProperty` will automatically
99
res, err := es.Indices.Create("test-index").
1010
Request(&create.Request{
1111
Mappings: &types.TypeMapping{
12-
Properties: map[types.PropertyName]types.PropertyBuilder{
13-
"price": types.NewIntegerNumberPropertyBuilder().Build(),
12+
Properties: map[string]types.Property{
13+
"price": types.NewIntegerNumberProperty(),
1414
},
1515
},
1616
}).

.doc/typedapi/examples/search.asciidoc

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ With a struct request:
99
res, err := es.Search().
1010
Index("index_name"). // <1>
1111
Request(&search.Request{ // <2>
12-
Query: &types.QueryContainer{
13-
Match: map[types.Field]types.MatchQuery{
12+
Query: &types.Query{
13+
Match: map[string]types.MatchQuery{
1414
"name": {Query: "Foo"}, // <3>
1515
},
1616
},
@@ -21,22 +21,7 @@ res, err := es.Search().
2121
<3> Match query specifies that `name` should match `Foo`.
2222
<4> The query is run with a `context.Background` and returns the response.
2323

24-
The same query using the builder:
25-
[source,go]
26-
-----
27-
res, err := es.Search().
28-
Index("index_name").
29-
Request(search.NewRequestBuilder().
30-
Query(types.NewQueryContainerBuilder().
31-
Match(map[types.Field]types.MatchQueryBuilder{
32-
"name": types.NewMatchQueryBuilder().
33-
Query("Foo"),
34-
})).
35-
Build(),
36-
).Do(context.Background())
37-
-----
38-
39-
Both of the examples produce the following JSON:
24+
It produces the following JSON:
4025

4126
[source,json]
4227
-----

.doc/typedapi/queries.asciidoc

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,14 @@ For example, a simple search request for a term "Foo" in the `name` field could
99
[source,go]
1010
-----
1111
search.Request{
12-
Query: &types.QueryContainer{
13-
Term: map[types.Field]types.TermQuery{
12+
Query: &types.Query{
13+
Term: map[string]types.TermQuery{
1414
"name": {Value: "Foo"},
1515
},
1616
},
1717
}
1818
-----
1919

20-
==== Query Builder
21-
22-
Although the structure syntax is lightweight, the types will sometimes lead you to pointers of string or even type aliases which ultimately are interfaces.
23-
For all those occasions as well as discoverability, we provide for the entire API a builder for each type; the request above can be written like this:
24-
25-
[source,go]
26-
-----
27-
ss := search.NewRequest().
28-
Query(
29-
types.NewQueryContainer().
30-
Term(map[types.Field]types.TermQuery{
31-
"name": types.NewTermQuery().Value("Foo").Build(),
32-
}).
33-
Build()).
34-
Build()
35-
-----
36-
37-
The builders are designed to take value arguments for easier inline use, you can mix at will the structures and the builder as you see fit depending on your usage.
38-
3920
==== Raw JSON
4021

4122
Lastly if you want to use your own pre-baked JSON queries using templates or even a specific encoder, you can pass the body directly to the `Raw` method of the endpoint:

0 commit comments

Comments
 (0)