@@ -27,26 +27,7 @@ Refer to the <<installation>> page to learn more.
2727[discrete]
2828=== Connecting
2929
30- You can connect to the Elastic Cloud using an API key and the Elasticsearch
31- endpoint for the low level API:
32-
33- [source,go]
34- ----
35- client, err := elasticsearch.NewClient(elasticsearch.Config{
36- CloudID: "<CloudID>",
37- APIKey: "<ApiKey>",
38- })
39- ----
40-
41- This is the same for the fully-typed API:
42-
43- [source,go]
44- ----
45- typedClient, err := elasticsearch.NewTypedClient(elasticsearch.Config{
46- CloudID: "<CloudID>",
47- APIKey: "<ApiKey>",
48- })
49- ----
30+ include::tab-widgets/connecting-widget.asciidoc[]
5031
5132
5233Your Elasticsearch endpoint can be found on the **My deployment** page of your
@@ -72,153 +53,43 @@ examples, refer to the <<examples>> page.
7253[discrete]
7354==== Creating an index
7455
75- This is how you create the `my_index` index with the low level API:
76-
77- [source,go]
78- ----
79- client.Indices.Create("my_index")
80- ----
81-
82- This is how you create the `my_index` index with the fully-typed API:
83-
84- [source,go]
85- ----
86- typedClient.Indices.Create("my_index").Do(context.TODO())
87- ----
56+ include::tab-widgets/create-index-widget.asciidoc[]
8857
8958
9059[discrete]
9160==== Indexing documents
9261
93- This is a simple way of indexing a document by using the low-level API:
94-
95- [source,go]
96- ----
97- document := struct {
98- Name string `json:"name"`
99- }{
100- "go-elasticsearch",
101- }
102- data, _ := json.Marshal(document)
103- client.Index("my_index", bytes.NewReader(data))
104- ----
105-
106- The same operation by using the fully-typed API:
107-
108- [source,go]
109- ----
110- document := struct {
111- Name string `json:"name"`
112- }{
113- "go-elasticsearch",
114- }
115- typedClient.Index("my_index").
116- Id("1").
117- Request(document).
118- Do(context.TODO())
119- ----
62+ include::tab-widgets/index-document-widget.asciidoc[]
63+
12064
12165[discrete]
12266==== Getting documents
12367
124- You can get documents by using the following code with the low-level API:
125-
126- [source,go]
127- ----
128- client.Get("my_index", "id")
129- ----
130-
131- This is how you can get documents by using the fully-typed API:
132-
133- [source,go]
134- ----
135- typedClient.Get("my_index", "id").Do(context.TODO())
136- ----
68+ include::tab-widgets/get-documents-widget.asciidoc[]
13769
13870
13971[discrete]
14072==== Searching documents
14173
142- This is how you can create a single match query with the low-level API:
143-
144- [source,go]
145- ----
146- query := `{ "query": { "match_all": {} } }`
147- client.Search(
148- client.Search.WithIndex("my_index"),
149- client.Search.WithBody(strings.NewReader(query)),
150- )
151- ----
152-
153- You can perform a single match query with the fully-typed API, too:
154-
155- [source,go]
156- ----
157- typedClient.Search().
158- Index("my_index").
159- Request(&search.Request{
160- Query: &types.Query{MatchAll: &types.MatchAllQuery{}},
161- }).
162- Do(context.TODO())
163- ----
74+ include::tab-widgets/search-documents-widget.asciidoc[]
16475
16576
16677[discrete]
16778==== Updating documents
16879
169- This is how you can update a document, for example to add a new field, by using
170- the low-level API:
171-
172- [source,go]
173- ----
174- client.Update("my_index", "id", strings.NewReader(`{doc: { language: "Go" }}`))
175- ----
176-
177- And this is how you can update a document with the fully-typed API:
178-
179- [source,go]
180- ----
181- typedClient.Update("my_index", "id").
182- Request(&update.Request{
183- Doc: json.RawMessage(`{ language: "Go" }`),
184- }).Do(context.TODO())
185- ----
80+ include::tab-widgets/update-documents-widget.asciidoc[]
18681
18782
18883[discrete]
18984==== Deleting documents
19085
191- Low-level API:
192-
193- [source,go]
194- ----
195- client.Delete("my_index", "id")
196- ----
197-
198- Fully-typed API:
199-
200- [source,go]
201- ----
202- typedClient.Delete("my_index", "id").Do(context.TODO())
203- ----
86+ include::tab-widgets/delete-documents-widget.asciidoc[]
20487
20588
20689[discrete]
20790==== Deleting an index
20891
209- Low-level API:
210-
211- [source,go]
212- ----
213- client.Indices.Delete([]string{"my_index"})
214- ----
215-
216- Fully-typed API:
217-
218- [source,go]
219- ----
220- typedClient.Indices.Delete("my_index").Do(context.TODO())
221- ----
92+ include::tab-widgets/delete-index-widget.asciidoc[]
22293
22394
22495[discrete]
0 commit comments