Skip to content

Commit 1e505d0

Browse files
committed
Bump docs references to v9
1 parent 47ac227 commit 1e505d0

File tree

5 files changed

+218
-13
lines changed

5 files changed

+218
-13
lines changed

docs/reference/connecting.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ This section illustrates the best practices for leveraging the {{es}} client in
236236
package httpexample
237237

238238
import (
239-
"github.com/elastic/go-elasticsearch/v8"
239+
"github.com/elastic/go-elasticsearch/v9"
240240
)
241241

242242
var client *elasticsearch.Client
@@ -264,7 +264,7 @@ package httpexample
264264

265265
import (
266266
"github.com/aws/aws-lambda-go/lambda"
267-
"github.com/elastic/go-elasticsearch/v8"
267+
"github.com/elastic/go-elasticsearch/v9"
268268
)
269269

270270
var client *elasticsearch.Client

docs/reference/esql.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ import (
5959
"fmt"
6060
"log"
6161

62-
"github.com/elastic/go-elasticsearch/v8"
63-
"github.com/elastic/go-elasticsearch/v8/typedapi/esql/query"
62+
"github.com/elastic/go-elasticsearch/v9"
63+
"github.com/elastic/go-elasticsearch/v9/typedapi/esql/query"
6464
)
6565

6666
type Book struct {
Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
1+
---
2+
mapped_pages:
3+
- https://www.elastic.co/guide/en/serverless/current/elasticsearch-go-client-getting-started.html
4+
navigation_title: Getting started in {{serverless-short}}
5+
---
6+
7+
# Getting started with {{es}} Go in {{serverless-full}}[elasticsearch-go-client-getting-started]
8+
9+
This page guides you through the installation process of the {{es}} Go client, shows you how to initialize the client, and how to perform basic {{es}} operations with it.
10+
11+
12+
## Requirements [elasticsearch-go-client-getting-started-requirements]
13+
14+
* Go 1.22 or higher installed on your system.
15+
16+
17+
## Installation [elasticsearch-go-client-getting-started-installation]
18+
19+
20+
### Using the command line [elasticsearch-go-client-getting-started-using-the-command-line]
21+
22+
You can install the Go client with the following commands:
23+
24+
```bash
25+
go get -u github.com/elastic/go-elasticsearch/v9@latest
26+
```
27+
28+
29+
## Imports [elasticsearch-go-client-getting-started-imports]
30+
31+
The following snippets use these imports:
32+
33+
```go
34+
import (
35+
"context"
36+
"encoding/json"
37+
"fmt"
38+
"log"
39+
"strconv"
40+
41+
"github.com/elastic/go-elasticsearch/v9"
42+
"github.com/elastic/go-elasticsearch/v9/typedapi/types"
43+
"github.com/elastic/go-elasticsearch/v9/typedapi/types/enums/result"
44+
)
45+
```
46+
47+
48+
## Initialize the client [elasticsearch-go-client-getting-started-initialize-the-client]
49+
50+
Initialize the client using your API key and {{es}} endpoint:
51+
52+
```go
53+
client, err := elasticsearch.NewTypedClient(elasticsearch.Config{
54+
Addresses: []string{"https://my-project-url"},
55+
APIKey: "your-api-key",
56+
})
57+
if err != nil {
58+
log.Fatalf("Error creating the client: %s", err)
59+
}
60+
```
61+
62+
To get API keys for the {{es}} endpoint for a project, see [Get started](docs-content://solutions/search/get-started.md).
63+
64+
65+
## Using the API [elasticsearch-go-client-getting-started-using-the-api]
66+
67+
After you’ve initialized the client, you can start ingesting documents. You can use the `bulk` API for this. This API enables you to index, update, and delete several documents in one request.
68+
69+
70+
### Creating an index and ingesting documents [elasticsearch-go-client-getting-started-creating-an-index-and-ingesting-documents]
71+
72+
You can call the `bulk` API with a body parameter, an array of hashes that define the action, and a document.
73+
74+
The following is an example of indexing some classic books into the `books` index:
75+
76+
```go
77+
type Book struct {
78+
Name string `json:"name"`
79+
Author string `json:"author"`
80+
ReleaseDate string `json:"release_date"`
81+
PageCount int `json:"page_count"`
82+
}
83+
84+
books := []Book{
85+
{Name: "Snow Crash", Author: "Neal Stephenson", ReleaseDate: "1992-06-01", PageCount: 470},
86+
{Name: "Revelation Space", Author: "Alastair Reynolds", ReleaseDate: "2000-03-15", PageCount: 585},
87+
{Name: "1984", Author: "George Orwell", ReleaseDate: "1949-06-08", PageCount: 328},
88+
{Name: "Fahrenheit 451", Author: "Ray Bradbury", ReleaseDate: "1953-10-15", PageCount: 227},
89+
{Name: "Brave New World", Author: "Aldous Huxley", ReleaseDate: "1932-06-01", PageCount: 268},
90+
{Name: "The Handmaid's Tale", Author: "Margaret Atwood", ReleaseDate: "1985-06-01", PageCount: 311},
91+
}
92+
indexName := "books"
93+
94+
bulk := client.Bulk()
95+
for i, book := range books {
96+
id := strconv.Itoa(i)
97+
err := bulk.CreateOp(types.CreateOperation{Index_: &indexName, Id_: &id}, book)
98+
if err != nil {
99+
log.Fatal(err)
100+
}
101+
}
102+
bulkRes, err := bulk.Do(context.TODO())
103+
if err != nil {
104+
log.Fatal(err)
105+
}
106+
107+
fmt.Printf("Bulk: %#v\n", bulkRes.Items)
108+
```
109+
110+
When you use the client to make a request to {{es-serverless}}, it returns an API response object. You can access the body values directly as seen on the previous example with `bulkRes`.
111+
112+
113+
### Getting documents [elasticsearch-go-client-getting-started-getting-documents]
114+
115+
You can get documents by using the following code:
116+
117+
```go
118+
getRes, err := client.Get(indexName, "5").Do(context.TODO())
119+
if err != nil {
120+
log.Fatal(err)
121+
}
122+
book := Book{}
123+
if err := json.Unmarshal(getRes.Source_, &book); err != nil {
124+
log.Fatal(err)
125+
}
126+
fmt.Printf("Get book: %#v\n", book)
127+
```
128+
129+
130+
### Searching [elasticsearch-go-client-getting-started-searching]
131+
132+
Now that some data is available, you can search your documents using the `search` API:
133+
134+
```go
135+
searchRes, err := client.Search().
136+
Index("books").
137+
Q("snow").
138+
Do(context.TODO())
139+
if err != nil {
140+
log.Fatal(err)
141+
}
142+
143+
bookSearch := []Book{}
144+
for _, hit := range searchRes.Hits.Hits {
145+
book := Book{}
146+
if err := json.Unmarshal(hit.Source_, &book); err != nil {
147+
log.Fatal(err)
148+
}
149+
bookSearch = append(bookSearch, book)
150+
}
151+
fmt.Printf("Search books: %#v\n", bookSearch)
152+
```
153+
154+
155+
### Updating a document [elasticsearch-go-client-getting-started-updating-a-document]
156+
157+
You can call the `Update` API to update a document, in this example updating the `page_count` for "The Handmaid’s Tale" with id "5":
158+
159+
```go
160+
updateRes, err := client.Update("books", "5").
161+
Doc(
162+
struct {
163+
PageCount int `json:"page_count"`
164+
}{PageCount: 312},
165+
).
166+
Do(context.TODO())
167+
if err != nil {
168+
log.Fatal(err)
169+
}
170+
171+
if updateRes.Result == result.Updated {
172+
fmt.Printf("Update book: %#v\n", updateRes)
173+
}
174+
```
175+
176+
177+
### Deleting a document [elasticsearch-go-client-getting-started-deleting-a-document]
178+
179+
You can call the `Delete` API to delete a document:
180+
181+
```go
182+
deleteRes, err := client.Delete("books", "5").Do(context.TODO())
183+
if err != nil {
184+
log.Fatal(err)
185+
}
186+
187+
if deleteRes.Result == result.Deleted {
188+
fmt.Printf("Delete book: %#v\n", deleteRes)
189+
}
190+
```
191+
192+
193+
### Deleting an index [elasticsearch-go-client-getting-started-deleting-an-index]
194+
195+
```go
196+
indexDeleteRes, err := client.Indices.Delete("books").Do(context.TODO())
197+
if err != nil {
198+
log.Fatal(err)
199+
}
200+
201+
if indexDeleteRes.Acknowledged {
202+
fmt.Printf("Delete index: %#v\n", indexDeleteRes)
203+
}
204+
```
205+

docs/reference/getting-started.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Go version 1.21+
1818
To install the latest version of the client, run the following command:
1919

2020
```shell
21-
go get github.com/elastic/go-elasticsearch/v8@latest
21+
go get github.com/elastic/go-elasticsearch/v9@latest
2222
```
2323

2424
Refer to the [*Installation*](/reference/installation.md) page to learn more.

docs/reference/installation.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ mapped_pages:
88
To install the 8.x version of the client, add the package to your `go.mod` file:
99

1010
```text
11-
require github.com/elastic/go-elasticsearch/v8 8.5
11+
require github.com/elastic/go-elasticsearch/v9 9.0
1212
```
1313

1414
Or, clone the repository:
1515

1616
```text
17-
git clone --branch 8.5 https://github.com/elastic/go-elasticsearch.git $GOPATH/src/github
17+
git clone --branch 9.0 https://github.com/elastic/go-elasticsearch.git $GOPATH/src/github
1818
```
1919

2020
To install another version, modify the path or the branch name accordingly. The client major versions correspond to the {{es}} major versions.
@@ -27,7 +27,7 @@ mkdir my-elasticsearch-app && cd my-elasticsearch-app
2727
cat > go.mod <<-END
2828
module my-elasticsearch-app
2929
30-
require github.com/elastic/go-elasticsearch/v8 main
30+
require github.com/elastic/go-elasticsearch/v9 main
3131
END
3232
3333
cat > main.go <<-END
@@ -36,7 +36,7 @@ cat > main.go <<-END
3636
import (
3737
"log"
3838
39-
"github.com/elastic/go-elasticsearch/v8"
39+
"github.com/elastic/go-elasticsearch/v9"
4040
)
4141
4242
func main() {
@@ -55,8 +55,8 @@ go run main.go
5555
The language clients are forward compatible; meaning that the clients support communicating with greater or equal minor versions of {{es}} without breaking. It does not mean that the clients automatically support new features of newer {{es}} versions; it is only possible after a release of a new client version. For example, a 8.12 client version won’t automatically support the new features of the 8.13 version of {{es}}, the 8.13 client version is required for that. {{es}} language clients are only backwards compatible with default distributions and without guarantees made.
5656

5757
| Elasticsearch Version | Elasticsearch-Go Branch | Supported |
58-
| --- | --- | --- |
59-
| main | main | |
60-
| 8.x | 8.x | 8.x |
61-
| 7.x | 7.x | 7.17 |
58+
|-----------------------|-------------------------|-----------|
59+
| main | main | |
60+
| 9.x | 9.x | 9.x |
61+
| 8.x | 8.x | 8.x |
6262

0 commit comments

Comments
 (0)