﻿---
title: Getting started
description: This page guides you through the installation process of the Go client, shows you how to instantiate the client, and how to perform basic Elasticsearch...
url: https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/getting-started
products:
  - Elasticsearch
  - Elasticsearch Client
  - Elasticsearch Go Client
---

# Getting started
This page guides you through the installation process of the Go client, shows you how to instantiate the client, and how to perform basic Elasticsearch operations with it. The examples use the [typed API](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/typed-api) with the [`esdsl`](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/typed-api/esdsl) query builders, which is the recommended way to use the client. If you need raw-JSON control or an endpoint not yet covered by the typed API, see the [low-level API](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/low-level-api).

## Requirements

Go version 1.24+

## Installation

To install the latest version of the client, run the following command:
```shell
go get github.com/elastic/go-elasticsearch/v9@latest
```

Refer to the [_Installation_](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/installation) page to learn more.

## Connecting

Connect to Elastic Cloud using an API key and the Elasticsearch endpoint:
```go
client, err := elasticsearch.NewTyped(
    elasticsearch.WithCloudID("<CloudID>"),
    elasticsearch.WithAPIKey("<ApiKey>"),  
)
```

Your Elasticsearch endpoint can be found on the **My deployment** page of your deployment:
![Finding Elasticsearch endpoint](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/images/es-endpoint.jpg)
You can generate an API key on the **Management** page under Security.
![Create API key](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/images/create-api-key.png)
For other connection options, refer to the [_Connecting_](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/connecting) section.

## Operations

Time to use Elasticsearch! This section walks you through the basic, and most important, operations of Elasticsearch. For more operations and more advanced examples, refer to the [Using the API](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/using-the-api) section.
<stepper>
  <step title="Create an index">
    ```go
    client.Indices.Create("my_index").Do(context.TODO())
    ```
  </step>

  <step title="Index a document">
    ```go
    document := struct {
        Name string `json:"name"`
    }{
        "go-elasticsearch",
    }
    client.Index("my_index").
        Id("1").
        Document(document).
        Do(context.TODO())
    ```
  </step>

  <step title="Get a document">
    ```go
    client.Get("my_index", "1").Do(context.TODO())
    ```
  </step>

  <step title="Search documents">
    Use the [`esdsl`](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/typed-api/esdsl) builders for a concise, fluent query syntax:
    ```go
    client.Search().
        Index("my_index").
        Query(esdsl.NewMatchAllQuery()).
        Do(context.TODO())
    ```
  </step>

  <step title="Update a document">
    ```go
    client.Update("my_index", "1").
        Request(&update.Request{
            Doc: json.RawMessage(`{"language": "Go"}`),
        }).Do(context.TODO())
    ```
  </step>

  <step title="Delete a document">
    ```go
    client.Delete("my_index", "1").Do(context.TODO())
    ```
  </step>

  <step title="Delete an index">
    ```go
    client.Indices.Delete("my_index").Do(context.TODO())
    ```
  </step>
</stepper>


## Further reading

- Learn more about the [_Typed API_](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/typed-api), a strongly typed Go API for Elasticsearch.
- Explore the [_esdsl builders_](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/typed-api/esdsl) for a fluent syntax to construct queries, aggregations, and mappings.
- If you need the low-level API or are migrating from it, see the [_Low-level API_](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/low-level-api) and the [_migration guide_](https://www.elastic.co/elastic/docs-builder/docs/3175/reference/elasticsearch/clients/go/low-level-api/migration).