Skip to content

Commit

Permalink
Merge pull request #3 from elastic/staging-migration
Browse files Browse the repository at this point in the history
Relocate files from staging repos
  • Loading branch information
shainaraskas authored May 22, 2024
2 parents 3c7548b + 9680beb commit a7bed94
Show file tree
Hide file tree
Showing 192 changed files with 11,897 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -1 +1 @@
* @elastic/platform-docs
* @elastic/platform-docs
25 changes: 25 additions & 0 deletions .github/workflows/docs-elastic-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# name: Docs

# on:
# pull_request_target:
# paths:
# - '**.mdx'
# - '**.docnav.json'
# - '**.docapi.json'
# - '**.devdocs.json'
# - '**.jpg'
# - '**.jpeg'
# - '**.png'
# - '**.svg'
# - '**.gif'
# types: [opened, closed, synchronize]

# jobs:
# publish:
# name: Vercel Build Check
# uses: elastic/workflows/.github/workflows/docs-elastic-co-publish.yml@main
# secrets:
# VERCEL_GITHUB_TOKEN: ${{ secrets.VERCEL_GITHUB_TOKEN }}
# VERCEL_TOKEN: ${{ secrets.VERCEL_TOKEN }}
# VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
# VERCEL_PROJECT_ID_DOCS_CO: ${{ secrets.VERCEL_PROJECT_ID_DOCS_CO }}
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# vscode stuff
.vscode/

# vs stuff
.vs/

# osx stuff
.DS_Store

# jetbrains
*.iml
.idea
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ This documentation uses a custom syntax written in [MDX](https://mdxjs.com/). In

## Preview the docs

When you open a PR, a preview is automatically generated. A link to the preview is added as a comment.
When you open a PR, a preview is automatically generated. A link to the preview is added as a comment.
127 changes: 127 additions & 0 deletions docs/client-libraries/clients-dot-net-getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
---
id: serverlessElasticsearchDotNetGettingStarted
slug: /serverless/elasticsearch/dot-net-client-getting-started
title: Get started with the serverless .NET client
description: Set up and use the .NET client for ((es3)).
tags: [ 'serverless', 'elasticsearch', '.net', 'how to' ]
---

<DocBadge template="technical preview" />

This page guides you through the installation process of the
.NET client for ((es3)), shows you how to initialize the client, and how to perform basic
((es)) operations with it.


## Requirements

* .NET Core, .NET 5+ or .NET Framework (4.6.1 and higher).


## Installation

You can install the .NET client with the following command:

```bash
dotnet add package Elastic.Clients.Elasticsearch.Serverless
```


## Initialize the client

Initialize the client using your API key and Elasticsearch Endpoint:

```net
var client = new ElasticsearchClient("<CLOUD_ID>", new ApiKey("<API_KEY>"));
```

To get API keys or the Elasticsearch Endpoint for a project, see <DocLink id="serverlessElasticsearchGetStarted" />.


## Using the API

After you've initialized the client, you can create an index and start ingesting
documents.


### Creating an index and ingesting documents

The following is an example of creating a `my_index` index:

```net
var response = await client.Indices.CreateAsync("my_index");
```

This is a simple way of indexing a document into `my_index`:

```net
var doc = new MyDoc
{
Id = 1,
User = "xyz_user",
Message = "Trying out the client, so far so good?"
};
var response = await client.IndexAsync(doc, "my_index");
```


### Getting documents

You can get documents by using the following code:

```net
var response = await client.GetAsync<MyDoc>(id, idx => idx.Index("my_index"));
if (response.IsValidResponse)
{
var doc = response.Source;
}
```


### Searching

This is how you can create a single match query with the .NET client:

```net
var response = await client.SearchAsync<MyDoc>(s => s
.Index("my_index")
.From(0)
.Size(10)
.Query(q => q
.Term(t => t.User, "flobernd")
)
);
if (response.IsValidResponse)
{
var doc = response.Documents.FirstOrDefault();
}
```


### Updating a document

This is how you can update a document, for example to add a new field:

```net
doc.Message = "This is a new message";
var response = await client.UpdateAsync<MyDoc, MyDoc>("my_index", 1, u => u
.Doc(doc));
```

### Deleting a document

```net
var response = await client.DeleteAsync("my_index", 1);
```


### Deleting an index


```net
var response = await client.Indices.DeleteAsync("my_index");
```
215 changes: 215 additions & 0 deletions docs/client-libraries/clients-go-getting-started.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,215 @@
---
id: serverlessElasticsearchGoGettingStarted
slug: /serverless/elasticsearch/go-client-getting-started
title: Get started with the serverless Go Client
description: Set up and use the Go client for ((es3)).
tags: [ 'serverless', 'elasticsearch', 'go', 'how to' ]
---

<DocBadge template="technical preview" />
This page guides you through the installation process of the Go
client for ((es3)), shows you how to initialize the client, and how to perform basic
((es)) operations with it.


## Requirements

* Go 1.20 or higher installed on your system.


## Installation


### Using the command line

You can install the Go client with the following
commands:

```bash
go get -u github.com/elastic/elasticsearch-serverless-go@latest
```


## Imports

The following snippets use these imports:

```go
import (
"context"
"encoding/json"
"fmt"
"log"
"strconv"

"github.com/elastic/elasticsearch-serverless-go"
"github.com/elastic/elasticsearch-serverless-go/typedapi/types"
"github.com/elastic/elasticsearch-serverless-go/typedapi/types/enums/result"
)
```


## Initialize the client

Initialize the client using your API key and Elasticsearch Endpoint:

```go
client, err := elasticsearch.NewClient(elasticsearch.Config{
APIKey: "you_api_key",
Address: "https://my-project-url",
})
if err != nil {
log.Fatal(err)
}
```

To get API keys or the Elasticsearch Endpoint for a project, see <DocLink id="serverlessElasticsearchGetStarted" />.


## Using the API

After you've initialized the client, you can start ingesting documents. You can
use the `bulk` API for this. This API enables you to index, update, and delete
several documents in one request.


### Creating an index and ingesting documents

You can call the `bulk` API with a body parameter, an array of hashes that
define the action, and a document.

The following is an example of indexing some classic books into the `books`
index:

```go
type Book struct {
Name string `json:"name"`
Author string `json:"author"`
ReleaseDate string `json:"release_date"`
PageCount int `json:"page_count"`
}

books := []Book{
{Name: "Snow Crash", Author: "Neal Stephenson", ReleaseDate: "1992-06-01", PageCount: 470},
{Name: "Revelation Space", Author: "Alastair Reynolds", ReleaseDate: "2000-03-15", PageCount: 585},
{Name: "1984", Author: "George Orwell", ReleaseDate: "1949-06-08", PageCount: 328},
{Name: "Fahrenheit 451", Author: "Ray Bradbury", ReleaseDate: "1953-10-15", PageCount: 227},
{Name: "Brave New World", Author: "Aldous Huxley", ReleaseDate: "1932-06-01", PageCount: 268},
{Name: "The Handmaid's Tale", Author: "Margaret Atwood", ReleaseDate: "1985-06-01", PageCount: 311},
}
indexName := "books"

bulk := client.Bulk()
for i, book := range books {
id := strconv.Itoa(i)
err := bulk.CreateOp(types.CreateOperation{Index_: &indexName, Id_: &id}, book)
if err != nil {
log.Fatal(err)
}
}
bulkRes, err := bulk.Do(context.TODO())
if err != nil {
log.Fatal(err)
}

fmt.Printf("Bulk: %#v\n", bulkRes.Items)
```

When you use the client to make a request to ((es)), it returns an API
response object. You can access the body values directly as seen on
the previous example with `bulkRes`.


### Getting documents

You can get documents by using the following code:

```go
getRes, err := client.Get(indexName, "5").Do(context.TODO())
if err != nil {
log.Fatal(err)
}
book := Book{}
if err := json.Unmarshal(getRes.Source_, &book); err != nil {
log.Fatal(err)
}
fmt.Printf("Get book: %#v\n", book)
```


### Searching

Now that some data is available, you can search your documents using the
`search` API:

```go
searchRes, err := client.Search().
Index("books").
Q("snow").
Do(context.TODO())
if err != nil {
log.Fatal(err)
}

bookSearch := []Book{}
for _, hit := range searchRes.Hits.Hits {
book := Book{}
if err := json.Unmarshal(hit.Source_, &book); err != nil {
log.Fatal(err)
}
bookSearch = append(bookSearch, book)
}
fmt.Printf("Search books: %#v\n", bookSearch)
```

### Updating a document

You can call the `Update` API to update a document, in this example updating the
`page_count` for "The Handmaid's Tale" with id "5":

```go
updateRes, err := client.Update("books", "5").
Doc(
struct {
PageCount int `json:"page_count"`
}{PageCount: 312},
).
Do(context.TODO())
if err != nil {
log.Fatal(err)
}

if updateRes.Result == result.Updated {
fmt.Printf("Update book: %#v\n", updateRes)
}
```

### Deleting a document

You can call the `Delete` API to delete a document:

```go
deleteRes, err := client.Delete("books", "5").Do(context.TODO())
if err != nil {
log.Fatal(err)
}

if deleteRes.Result == result.Deleted {
fmt.Printf("Delete book: %#v\n", deleteRes)
}
```


### Deleting an index


```go
indexDeleteRes, err := client.Indices.Delete("books").Do(context.TODO())
if err != nil {
log.Fatal(err)
}

if indexDeleteRes.Acknowledged {
fmt.Printf("Delete index: %#v\n", indexDeleteRes)
}
```
Loading

0 comments on commit a7bed94

Please sign in to comment.