Skip to content

Commit 0fba0e4

Browse files
authored
[DOCS] Adds context selector widget to the getting started page. (#751)
1 parent 525f3e8 commit 0fba0e4

17 files changed

+524
-138
lines changed

.doc/getting-started.asciidoc

Lines changed: 9 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -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

5233
Your 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]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
++++
2+
<div class="tabs" data-tab-group="go-get-started">
3+
<div role="tablist" aria-label="go-get-started">
4+
<button role="tab"
5+
aria-selected="true"
6+
aria-controls="low-level-api-tab-connecting"
7+
id="low-level-api-connecting">
8+
Low-level API
9+
</button>
10+
<button role="tab"
11+
aria-selected="false"
12+
aria-controls="fully-typed-api-tab-connecting"
13+
id="fully-typed-api-connecting">
14+
Fully-typed API
15+
</button>
16+
</div>
17+
<div tabindex="0"
18+
role="tabpanel"
19+
id="low-level-api-tab-connecting"
20+
aria-labelledby="low-level-api-connecting">
21+
++++
22+
23+
include::connecting.asciidoc[tag=low-level]
24+
25+
++++
26+
</div>
27+
<div tabindex="0"
28+
role="tabpanel"
29+
id="fully-typed-api-tab-connecting"
30+
aria-labelledby="fully-typed-api-connecting"
31+
hidden="">
32+
++++
33+
34+
include::connecting.asciidoc[tag=fully-typed]
35+
36+
++++
37+
</div>
38+
</div>
39+
++++
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// tag::low-level[]
2+
3+
You can connect to the Elastic Cloud using an API key and the Elasticsearch
4+
endpoint for the low level API:
5+
6+
[source,go]
7+
----
8+
client, err := elasticsearch.NewClient(elasticsearch.Config{
9+
CloudID: "<CloudID>",
10+
APIKey: "<ApiKey>",
11+
})
12+
----
13+
14+
// end::low-level[]
15+
16+
17+
// tag::fully-typed[]
18+
19+
You can connect to the Elastic Cloud using an API key and the Elasticsearch
20+
endpoint for the fully-typed API:
21+
22+
[source,go]
23+
----
24+
typedClient, err := elasticsearch.NewTypedClient(elasticsearch.Config{
25+
CloudID: "<CloudID>",
26+
APIKey: "<ApiKey>",
27+
})
28+
----
29+
30+
// end::fully-typed[]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
++++
2+
<div class="tabs" data-tab-group="go-get-started">
3+
<div role="tablist" aria-label="go-get-started">
4+
<button role="tab"
5+
aria-selected="true"
6+
aria-controls="low-level-api-tab-create-index"
7+
id="low-level-api-create-index">
8+
Low-level API
9+
</button>
10+
<button role="tab"
11+
aria-selected="false"
12+
aria-controls="fully-typed-api-tab-create-index"
13+
id="fully-typed-api-create-index">
14+
Fully-typed API
15+
</button>
16+
</div>
17+
<div tabindex="0"
18+
role="tabpanel"
19+
id="low-level-api-tab-create-index"
20+
aria-labelledby="low-level-api-create-index">
21+
++++
22+
23+
include::create-index.asciidoc[tag=low-level]
24+
25+
++++
26+
</div>
27+
<div tabindex="0"
28+
role="tabpanel"
29+
id="fully-typed-api-tab-create-index"
30+
aria-labelledby="fully-typed-api-create-index"
31+
hidden="">
32+
++++
33+
34+
include::create-index.asciidoc[tag=fully-typed]
35+
36+
++++
37+
</div>
38+
</div>
39+
++++
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// tag::low-level[]
2+
3+
This is how you create the `my_index` index with the low level API:
4+
5+
[source,go]
6+
----
7+
client.Indices.Create("my_index")
8+
----
9+
10+
// end::low-level[]
11+
12+
13+
// tag::fully-typed[]
14+
15+
This is how you create the `my_index` index with the fully-typed API:
16+
17+
[source,go]
18+
----
19+
typedClient.Indices.Create("my_index").Do(context.TODO())
20+
----
21+
22+
// end::fully-typed[]
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
++++
2+
<div class="tabs" data-tab-group="go-get-started">
3+
<div role="tablist" aria-label="go-get-started">
4+
<button role="tab"
5+
aria-selected="true"
6+
aria-controls="low-level-api-tab-delete-document"
7+
id="low-level-api-delete-document">
8+
Low-level API
9+
</button>
10+
<button role="tab"
11+
aria-selected="false"
12+
aria-controls="fully-typed-api-tab-delete-document"
13+
id="fully-typed-api-delete-document">
14+
Fully-typed API
15+
</button>
16+
</div>
17+
<div tabindex="0"
18+
role="tabpanel"
19+
id="low-level-api-tab-delete-document"
20+
aria-labelledby="low-level-api-delete-document">
21+
++++
22+
23+
include::delete-documents.asciidoc[tag=low-level]
24+
25+
++++
26+
</div>
27+
<div tabindex="0"
28+
role="tabpanel"
29+
id="fully-typed-api-tab-delete-document"
30+
aria-labelledby="fully-typed-api-delete-document"
31+
hidden="">
32+
++++
33+
34+
include::delete-documents.asciidoc[tag=fully-typed]
35+
36+
++++
37+
</div>
38+
</div>
39+
++++
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// tag::low-level[]
2+
3+
[source,go]
4+
----
5+
client.Delete("my_index", "id")
6+
----
7+
8+
// end::low-level[]
9+
10+
11+
// tag::fully-typed[]
12+
13+
[source,go]
14+
----
15+
typedClient.Delete("my_index", "id").Do(context.TODO())
16+
----
17+
18+
// end::fully-typed[]

0 commit comments

Comments
 (0)