Skip to content

Commit

Permalink
Linked user guides. (#302)
Browse files Browse the repository at this point in the history
Signed-off-by: dblock <[email protected]>
  • Loading branch information
dblock authored Apr 14, 2023
1 parent 07fe4f6 commit 76b7f8c
Show file tree
Hide file tree
Showing 2 changed files with 194 additions and 188 deletions.
203 changes: 15 additions & 188 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
- [User Guide](#user-guide)
- [Example](#example)
- [Amazon OpenSearch Service](#amazon-opensearch-service) - [AWS SDK V1](#aws-sdk-v1) - [AWS SDK V2](#aws-sdk-v2)
- [Data Streams API](#data-streams-api)
- [Create Data Stream](#create-data-streams)
- [Delete Data Stream](#delete-data-streams)
- [Get All Data Streams](#get-data-streams)
- [Get Specific Data Stream](#get-specific-data-streams)
- [Get Specific Data Stream Stats](#get-specific-data-streams-stats)
- [Example](#example)
- [Amazon OpenSearch Service](#amazon-opensearch-service)
- [AWS SDK v1](#aws-sdk-v1)
- [AWS SDK v2](#aws-sdk-v2)
- [Guides by Topic](#guides-by-topic)

# User Guide

Expand Down Expand Up @@ -180,7 +177,7 @@ To read more about SigV4 see [Signature Version 4 signing process](https://docs.

Here are some Go samples that show how to sign each OpenSearch request and automatically search for AWS credentials from the ~/.aws folder or environment variables:

#### AWS SDK V1
### AWS SDK v1

```go
package main
Expand Down Expand Up @@ -232,7 +229,7 @@ func main() {
}
```

#### AWS SDK V2
### AWS SDK v2

Use the AWS SDK v2 for Go to authenticate with Amazon OpenSearch service.

Expand Down Expand Up @@ -328,182 +325,12 @@ func getCredentialProvider(accessKey, secretAccessKey, token string) aws.Credent

```

## Data Streams API
## Guides by Topic

### Create Data Streams

- Create new client

```
client, err := opensearch.NewDefaultClient()
if err != nil {
panic(err)
}
```

- Create template index

```
iPut := opensearchapi.IndicesPutIndexTemplateRequest{
Name: "demo-data-template",
Pretty: true,
Human: true,
ErrorTrace: true,
Body: strings.NewReader(`{"index_patterns": ["demo-*"], "data_stream": {}, "priority": 100} }`),
}
iPutResponse, err := iPut.Do(context.Background(), client)
```

- Prepare request object

```
es := opensearchapi.IndicesCreateDataStreamRequest{
Name: "demo-name",
Human: true,
Pretty: true,
ErrorTrace: true,
Header: map[string][]string{
"Content-Type": {"application/json"},
},
}
```

- Execute request

```
res, err := es.Do(context.TODO(), client)
if err != nil {
// do not panic in production code
panic(err)
}
```

- Try to read response

```
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
if err != nil {
// do not panic in production code
panic(err)
}
fmt.Println("Response Status Code: ", res.StatusCode)
fmt.Println("Response Headers: ", res.Header)
fmt.Println("Response Body: ", string(body))
```

- Successfully created data stream

```
Response Status Code: 200
Response Headers: map[Content-Length:[28] Content-Type:[application/json; charset=UTF-8]]
Response Body: {"acknowledged" : true}
```

### Delete Data Streams

- Create new client as previous example
- Prepare request object

```
opensearchapi.IndicesDeleteDataStreamRequest{
Name: "demo-name",
Pretty: true,
Human: true,
ErrorTrace: true,
Header: map[string][]string{
"Content-Type": {"application/json"},
},
}
```

- Execute request as previous example
- Try to read response as previous example
- Successfully deleted data stream

```
Response Status Code: 200
Response Headers: map[Content-Length:[28] Content-Type:[application/json; charset=UTF-8]]
Response Body: {"acknowledged" : true}
```

### Get All Data Streams

- Create new client as previous example
- Prepare request object

```
r := opensearchapi.IndicesGetDataStreamRequest{
Pretty: true,
Human: true,
ErrorTrace: true,
Header: map[string][]string{
"Content-Type": {"application/json"},
},
}
```

- Execute request as previous example
- Try to read response as previous example
- Successfully retrieved data streams

```
Response Status Code: 200
Response Headers: map[Content-Length:[28] Content-Type:[application/json; charset=UTF-8]]
Response Body: {"data_streams":[{"name":"demo-name","timestamp_field":{"name":"@timestamp"},"indices":[{"index_name":".ds-demo-2023-03-21-23-33-46-000001","index_uuid":"NnzgqnP0ThS7LOMHJuZ-VQ"}],"generation":1,"status":"YELLOW","template":"demo-data-template"}]}
```

### Get Specific Data Stream

- Create new client as previous example
- Prepare request object

```
r := opensearchapi.IndicesGetDataStreamRequest{
Name: "demo-name",
Pretty: true,
Human: true,
ErrorTrace: true,
Header: map[string][]string{
"Content-Type": {"application/json"},
},
}
```

- Execute request as previous example
- Try to read response as previous example
- Successfully retrieved data stream

```
Response Status Code: 200
Response Headers: map[Content-Length:[28] Content-Type:[application/json; charset=UTF-8]]
Response Body: {"data_streams":[{"name":"demo-name","timestamp_field":{"name":"@timestamp"},"indices":[{"index_name":".ds-demo-2023-03-21-23-31-50-000001","index_uuid":"vhsowqdeRFCmr1GgQ7mIsQ"}],"generation":1,"status":"YELLOW","template":"demo-data-template"}]}
```

### Get Specific Data Stream Stats

- Create new client as as previous example
- Prepare request object

```
r := opensearchapi.IndicesGetDataStreamStatsRequest{
Name: "demo-name",
Pretty: true,
Human: true,
ErrorTrace: true,
Header: map[string][]string{
"Content-Type": {"application/json"},
},
}
```

- Execute request as previous example
- Try to read response as previous example
- Successfully retrieved data stream stats

```
Response Status Code: 200
Response Headers: map[Content-Length:[28] Content-Type:[application/json; charset=UTF-8]]
Response Body: {"_shards":{"total":2,"successful":1,"failed":0},"data_stream_count":1,"backing_indices":1,"total_store_size":"208b","total_store_size_bytes":208,"data_streams":[{"data_stream":"demo-name","backing_indices":1,"store_size":"208b","store_size_bytes":208,"maximum_timestamp":0}]}
```
- [Index Lifecycle](guides/index_lifecycle.md)
- [Document Lifecycle](guides/document_lifecycle.md)
- [Search](guides/search.md)
- [Bulk](guides/bulk.md)
- [Advanced Index Actions](guides/advanced_index_actions.md)
- [Index Templates](guides/index_template.md)
- [Data Streams](guides/data_streams.md)
Loading

0 comments on commit 76b7f8c

Please sign in to comment.