From e9782d95aef2aecd58e9175ff390f50126e32823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Istv=C3=A1n=20Zolt=C3=A1n=20Szab=C3=B3?= Date: Tue, 14 Nov 2023 16:31:58 +0100 Subject: [PATCH] [DOCS] Adds context selector widget to the getting started page. --- .doc/getting-started.asciidoc | 147 ++---------------- .doc/tab-widgets/connecting-widget.asciidoc | 39 +++++ .doc/tab-widgets/connecting.asciidoc | 30 ++++ .doc/tab-widgets/create-index-widget.asciidoc | 39 +++++ .doc/tab-widgets/create-index.asciidoc | 22 +++ .../delete-documents-widget.asciidoc | 39 +++++ .doc/tab-widgets/delete-documents.asciidoc | 18 +++ .doc/tab-widgets/delete-index-widget.asciidoc | 39 +++++ .doc/tab-widgets/delete-index.asciidoc | 18 +++ .../tab-widgets/get-documents-widget.asciidoc | 39 +++++ .doc/tab-widgets/get-documents.asciidoc | 22 +++ .../index-document-widget.asciidoc | 39 +++++ .doc/tab-widgets/index-document.asciidoc | 36 +++++ .../search-documents-widget.asciidoc | 39 +++++ .doc/tab-widgets/search-documents.asciidoc | 31 ++++ .../update-documents-widget.asciidoc | 39 +++++ .doc/tab-widgets/update-documents.asciidoc | 26 ++++ 17 files changed, 524 insertions(+), 138 deletions(-) create mode 100644 .doc/tab-widgets/connecting-widget.asciidoc create mode 100644 .doc/tab-widgets/connecting.asciidoc create mode 100644 .doc/tab-widgets/create-index-widget.asciidoc create mode 100644 .doc/tab-widgets/create-index.asciidoc create mode 100644 .doc/tab-widgets/delete-documents-widget.asciidoc create mode 100644 .doc/tab-widgets/delete-documents.asciidoc create mode 100644 .doc/tab-widgets/delete-index-widget.asciidoc create mode 100644 .doc/tab-widgets/delete-index.asciidoc create mode 100644 .doc/tab-widgets/get-documents-widget.asciidoc create mode 100644 .doc/tab-widgets/get-documents.asciidoc create mode 100644 .doc/tab-widgets/index-document-widget.asciidoc create mode 100644 .doc/tab-widgets/index-document.asciidoc create mode 100644 .doc/tab-widgets/search-documents-widget.asciidoc create mode 100644 .doc/tab-widgets/search-documents.asciidoc create mode 100644 .doc/tab-widgets/update-documents-widget.asciidoc create mode 100644 .doc/tab-widgets/update-documents.asciidoc diff --git a/.doc/getting-started.asciidoc b/.doc/getting-started.asciidoc index 79430649b2..37f2af4e45 100644 --- a/.doc/getting-started.asciidoc +++ b/.doc/getting-started.asciidoc @@ -27,26 +27,7 @@ Refer to the <> 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: "", - APIKey: "", -}) ----- - -This is the same for the fully-typed API: - -[source,go] ----- -typedClient, err := elasticsearch.NewTypedClient(elasticsearch.Config{ - CloudID: "", - APIKey: "", -}) ----- +include::tab-widgets/connecting-widget.asciidoc[] Your Elasticsearch endpoint can be found on the **My deployment** page of your @@ -72,153 +53,43 @@ examples, refer to the <> 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] diff --git a/.doc/tab-widgets/connecting-widget.asciidoc b/.doc/tab-widgets/connecting-widget.asciidoc new file mode 100644 index 0000000000..abc796c78d --- /dev/null +++ b/.doc/tab-widgets/connecting-widget.asciidoc @@ -0,0 +1,39 @@ +++++ +
+
+ + +
+
+++++ + +include::connecting.asciidoc[tag=low-level] + +++++ +
+ +
+++++ \ No newline at end of file diff --git a/.doc/tab-widgets/connecting.asciidoc b/.doc/tab-widgets/connecting.asciidoc new file mode 100644 index 0000000000..d2fbd8379c --- /dev/null +++ b/.doc/tab-widgets/connecting.asciidoc @@ -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: "", + 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: "", + APIKey: "", +}) +---- + +// end::fully-typed[] \ No newline at end of file diff --git a/.doc/tab-widgets/create-index-widget.asciidoc b/.doc/tab-widgets/create-index-widget.asciidoc new file mode 100644 index 0000000000..fbe20959b8 --- /dev/null +++ b/.doc/tab-widgets/create-index-widget.asciidoc @@ -0,0 +1,39 @@ +++++ +
+
+ + +
+
+++++ + +include::create-index.asciidoc[tag=low-level] + +++++ +
+ +
+++++ \ No newline at end of file diff --git a/.doc/tab-widgets/create-index.asciidoc b/.doc/tab-widgets/create-index.asciidoc new file mode 100644 index 0000000000..567a4d64c6 --- /dev/null +++ b/.doc/tab-widgets/create-index.asciidoc @@ -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[] \ No newline at end of file diff --git a/.doc/tab-widgets/delete-documents-widget.asciidoc b/.doc/tab-widgets/delete-documents-widget.asciidoc new file mode 100644 index 0000000000..d04a961236 --- /dev/null +++ b/.doc/tab-widgets/delete-documents-widget.asciidoc @@ -0,0 +1,39 @@ +++++ +
+
+ + +
+
+++++ + +include::delete-documents.asciidoc[tag=low-level] + +++++ +
+ +
+++++ \ No newline at end of file diff --git a/.doc/tab-widgets/delete-documents.asciidoc b/.doc/tab-widgets/delete-documents.asciidoc new file mode 100644 index 0000000000..e9de234f2e --- /dev/null +++ b/.doc/tab-widgets/delete-documents.asciidoc @@ -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[] \ No newline at end of file diff --git a/.doc/tab-widgets/delete-index-widget.asciidoc b/.doc/tab-widgets/delete-index-widget.asciidoc new file mode 100644 index 0000000000..9303a96d7c --- /dev/null +++ b/.doc/tab-widgets/delete-index-widget.asciidoc @@ -0,0 +1,39 @@ +++++ +
+
+ + +
+
+++++ + +include::delete-index.asciidoc[tag=low-level] + +++++ +
+ +
+++++ \ No newline at end of file diff --git a/.doc/tab-widgets/delete-index.asciidoc b/.doc/tab-widgets/delete-index.asciidoc new file mode 100644 index 0000000000..66e8812901 --- /dev/null +++ b/.doc/tab-widgets/delete-index.asciidoc @@ -0,0 +1,18 @@ +// tag::low-level[] + +[source,go] +---- +client.Indices.Delete([]string{"my_index"}) +---- + +// end::low-level[] + + +// tag::fully-typed[] + +[source,go] +---- +typedClient.Indices.Delete("my_index").Do(context.TODO()) +---- + +// end::fully-typed[] \ No newline at end of file diff --git a/.doc/tab-widgets/get-documents-widget.asciidoc b/.doc/tab-widgets/get-documents-widget.asciidoc new file mode 100644 index 0000000000..fbb0db0a22 --- /dev/null +++ b/.doc/tab-widgets/get-documents-widget.asciidoc @@ -0,0 +1,39 @@ +++++ +
+
+ + +
+
+++++ + +include::get-documents.asciidoc[tag=low-level] + +++++ +
+ +
+++++ \ No newline at end of file diff --git a/.doc/tab-widgets/get-documents.asciidoc b/.doc/tab-widgets/get-documents.asciidoc new file mode 100644 index 0000000000..9451f247fa --- /dev/null +++ b/.doc/tab-widgets/get-documents.asciidoc @@ -0,0 +1,22 @@ +// tag::low-level[] + +You can get documents by using the following code with the low-level API: + +[source,go] +---- +client.Get("my_index", "id") +---- + +// end::low-level[] + + +// tag::fully-typed[] + +This is how you can get documents by using the fully-typed API: + +[source,go] +---- +typedClient.Get("my_index", "id").Do(context.TODO()) +---- + +// end::fully-typed[] \ No newline at end of file diff --git a/.doc/tab-widgets/index-document-widget.asciidoc b/.doc/tab-widgets/index-document-widget.asciidoc new file mode 100644 index 0000000000..81c3f6a22f --- /dev/null +++ b/.doc/tab-widgets/index-document-widget.asciidoc @@ -0,0 +1,39 @@ +++++ +
+
+ + +
+
+++++ + +include::index-document.asciidoc[tag=low-level] + +++++ +
+ +
+++++ \ No newline at end of file diff --git a/.doc/tab-widgets/index-document.asciidoc b/.doc/tab-widgets/index-document.asciidoc new file mode 100644 index 0000000000..76dddab1a3 --- /dev/null +++ b/.doc/tab-widgets/index-document.asciidoc @@ -0,0 +1,36 @@ +// tag::low-level[] + +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)) +---- + +// end::low-level[] + + +// tag::fully-typed[] + +This is a simple way of indexing a documen 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()) +---- + +// end::fully-typed[] \ No newline at end of file diff --git a/.doc/tab-widgets/search-documents-widget.asciidoc b/.doc/tab-widgets/search-documents-widget.asciidoc new file mode 100644 index 0000000000..26cfdd23f9 --- /dev/null +++ b/.doc/tab-widgets/search-documents-widget.asciidoc @@ -0,0 +1,39 @@ +++++ +
+
+ + +
+
+++++ + +include::search-documents.asciidoc[tag=low-level] + +++++ +
+ +
+++++ \ No newline at end of file diff --git a/.doc/tab-widgets/search-documents.asciidoc b/.doc/tab-widgets/search-documents.asciidoc new file mode 100644 index 0000000000..f7f8a65187 --- /dev/null +++ b/.doc/tab-widgets/search-documents.asciidoc @@ -0,0 +1,31 @@ +// tag::low-level[] + +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)), +) +---- + +// end::low-level[] + + +// tag::fully-typed[] + +This is how you can perform a single match query with the fully-typed API: + +[source,go] +---- +typedClient.Search(). + Index("my_index"). + Request(&search.Request{ + Query: &types.Query{MatchAll: &types.MatchAllQuery{}}, + }). + Do(context.TODO()) +---- + +// end::fully-typed[] \ No newline at end of file diff --git a/.doc/tab-widgets/update-documents-widget.asciidoc b/.doc/tab-widgets/update-documents-widget.asciidoc new file mode 100644 index 0000000000..1f539e1987 --- /dev/null +++ b/.doc/tab-widgets/update-documents-widget.asciidoc @@ -0,0 +1,39 @@ +++++ +
+
+ + +
+
+++++ + +include::update-documents.asciidoc[tag=low-level] + +++++ +
+ +
+++++ \ No newline at end of file diff --git a/.doc/tab-widgets/update-documents.asciidoc b/.doc/tab-widgets/update-documents.asciidoc new file mode 100644 index 0000000000..f54025b285 --- /dev/null +++ b/.doc/tab-widgets/update-documents.asciidoc @@ -0,0 +1,26 @@ +// tag::low-level[] + +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" }}`)) +---- + +// end::low-level[] + + +// tag::fully-typed[] + +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()) +---- + +// end::fully-typed[] \ No newline at end of file