Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS] Adds context selector widget to the getting started page #751

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
147 changes: 9 additions & 138 deletions .doc/getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,7 @@ Refer to the <<installation>> page to learn more.
[discrete]
=== Connecting

You can connect to the Elastic Cloud using an API key and the Elasticsearch
endpoint for the low level API:

[source,go]
----
client, err := elasticsearch.NewClient(elasticsearch.Config{
CloudID: "<CloudID>",
APIKey: "<ApiKey>",
})
----

This is the same for the fully-typed API:

[source,go]
----
typedClient, err := elasticsearch.NewTypedClient(elasticsearch.Config{
CloudID: "<CloudID>",
APIKey: "<ApiKey>",
})
----
include::tab-widgets/connecting-widget.asciidoc[]


Your Elasticsearch endpoint can be found on the **My deployment** page of your
Expand All @@ -72,153 +53,43 @@ examples, refer to the <<examples>> page.
[discrete]
==== Creating an index

This is how you create the `my_index` index with the low level API:

[source,go]
----
client.Indices.Create("my_index")
----

This is how you create the `my_index` index with the fully-typed API:

[source,go]
----
typedClient.Indices.Create("my_index").Do(context.TODO())
----
include::tab-widgets/create-index-widget.asciidoc[]


[discrete]
==== Indexing documents

This is a simple way of indexing a document by using the low-level API:

[source,go]
----
document := struct {
Name string `json:"name"`
}{
"go-elasticsearch",
}
data, _ := json.Marshal(document)
client.Index("my_index", bytes.NewReader(data))
----

The same operation by using the fully-typed API:

[source,go]
----
document := struct {
Name string `json:"name"`
}{
"go-elasticsearch",
}
typedClient.Index("my_index").
Id("1").
Request(document).
Do(context.TODO())
----
include::tab-widgets/index-document-widget.asciidoc[]


[discrete]
==== Getting documents

You can get documents by using the following code with the low-level API:

[source,go]
----
client.Get("my_index", "id")
----

This is how you can get documents by using the fully-typed API:

[source,go]
----
typedClient.Get("my_index", "id").Do(context.TODO())
----
include::tab-widgets/get-documents-widget.asciidoc[]


[discrete]
==== Searching documents

This is how you can create a single match query with the low-level API:

[source,go]
----
query := `{ "query": { "match_all": {} } }`
client.Search(
client.Search.WithIndex("my_index"),
client.Search.WithBody(strings.NewReader(query)),
)
----

You can perform a single match query with the fully-typed API, too:

[source,go]
----
typedClient.Search().
Index("my_index").
Request(&search.Request{
Query: &types.Query{MatchAll: &types.MatchAllQuery{}},
}).
Do(context.TODO())
----
include::tab-widgets/search-documents-widget.asciidoc[]


[discrete]
==== Updating documents

This is how you can update a document, for example to add a new field, by using
the low-level API:

[source,go]
----
client.Update("my_index", "id", strings.NewReader(`{doc: { language: "Go" }}`))
----

And this is how you can update a document with the fully-typed API:

[source,go]
----
typedClient.Update("my_index", "id").
Request(&update.Request{
Doc: json.RawMessage(`{ language: "Go" }`),
}).Do(context.TODO())
----
include::tab-widgets/update-documents-widget.asciidoc[]


[discrete]
==== Deleting documents

Low-level API:

[source,go]
----
client.Delete("my_index", "id")
----

Fully-typed API:

[source,go]
----
typedClient.Delete("my_index", "id").Do(context.TODO())
----
include::tab-widgets/delete-documents-widget.asciidoc[]


[discrete]
==== Deleting an index

Low-level API:

[source,go]
----
client.Indices.Delete([]string{"my_index"})
----

Fully-typed API:

[source,go]
----
typedClient.Indices.Delete("my_index").Do(context.TODO())
----
include::tab-widgets/delete-index-widget.asciidoc[]


[discrete]
Expand Down
39 changes: 39 additions & 0 deletions .doc/tab-widgets/connecting-widget.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
++++
<div class="tabs" data-tab-group="go-get-started">
<div role="tablist" aria-label="go-get-started">
<button role="tab"
aria-selected="true"
aria-controls="low-level-api-tab-connecting"
id="low-level-api-connecting">
Low-level API
</button>
<button role="tab"
aria-selected="false"
aria-controls="fully-typed-api-tab-connecting"
id="fully-typed-api-connecting">
Fully-typed API
</button>
</div>
<div tabindex="0"
role="tabpanel"
id="low-level-api-tab-connecting"
aria-labelledby="low-level-api-connecting">
++++

include::connecting.asciidoc[tag=low-level]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="fully-typed-api-tab-connecting"
aria-labelledby="fully-typed-api-connecting"
hidden="">
++++

include::connecting.asciidoc[tag=fully-typed]

++++
</div>
</div>
++++
30 changes: 30 additions & 0 deletions .doc/tab-widgets/connecting.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// tag::low-level[]

You can connect to the Elastic Cloud using an API key and the Elasticsearch
endpoint for the low level API:

[source,go]
----
client, err := elasticsearch.NewClient(elasticsearch.Config{
CloudID: "<CloudID>",
APIKey: "<ApiKey>",
})
----

// end::low-level[]


// tag::fully-typed[]

You can connect to the Elastic Cloud using an API key and the Elasticsearch
endpoint for the fully-typed API:

[source,go]
----
typedClient, err := elasticsearch.NewTypedClient(elasticsearch.Config{
CloudID: "<CloudID>",
APIKey: "<ApiKey>",
})
----

// end::fully-typed[]
39 changes: 39 additions & 0 deletions .doc/tab-widgets/create-index-widget.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
++++
<div class="tabs" data-tab-group="go-get-started">
<div role="tablist" aria-label="go-get-started">
<button role="tab"
aria-selected="true"
aria-controls="low-level-api-tab-create-index"
id="low-level-api-create-index">
Low-level API
</button>
<button role="tab"
aria-selected="false"
aria-controls="fully-typed-api-tab-create-index"
id="fully-typed-api-create-index">
Fully-typed API
</button>
</div>
<div tabindex="0"
role="tabpanel"
id="low-level-api-tab-create-index"
aria-labelledby="low-level-api-create-index">
++++

include::create-index.asciidoc[tag=low-level]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="fully-typed-api-tab-create-index"
aria-labelledby="fully-typed-api-create-index"
hidden="">
++++

include::create-index.asciidoc[tag=fully-typed]

++++
</div>
</div>
++++
22 changes: 22 additions & 0 deletions .doc/tab-widgets/create-index.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// tag::low-level[]

This is how you create the `my_index` index with the low level API:

[source,go]
----
client.Indices.Create("my_index")
----

// end::low-level[]


// tag::fully-typed[]

This is how you create the `my_index` index with the fully-typed API:

[source,go]
----
typedClient.Indices.Create("my_index").Do(context.TODO())
----

// end::fully-typed[]
39 changes: 39 additions & 0 deletions .doc/tab-widgets/delete-documents-widget.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
++++
<div class="tabs" data-tab-group="go-get-started">
<div role="tablist" aria-label="go-get-started">
<button role="tab"
aria-selected="true"
aria-controls="low-level-api-tab-delete-document"
id="low-level-api-delete-document">
Low-level API
</button>
<button role="tab"
aria-selected="false"
aria-controls="fully-typed-api-tab-delete-document"
id="fully-typed-api-delete-document">
Fully-typed API
</button>
</div>
<div tabindex="0"
role="tabpanel"
id="low-level-api-tab-delete-document"
aria-labelledby="low-level-api-delete-document">
++++

include::delete-documents.asciidoc[tag=low-level]

++++
</div>
<div tabindex="0"
role="tabpanel"
id="fully-typed-api-tab-delete-document"
aria-labelledby="fully-typed-api-delete-document"
hidden="">
++++

include::delete-documents.asciidoc[tag=fully-typed]

++++
</div>
</div>
++++
18 changes: 18 additions & 0 deletions .doc/tab-widgets/delete-documents.asciidoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// tag::low-level[]

[source,go]
----
client.Delete("my_index", "id")
----

// end::low-level[]


// tag::fully-typed[]

[source,go]
----
typedClient.Delete("my_index", "id").Do(context.TODO())
----

// end::fully-typed[]
Loading
Loading