[[endpoints]]
==== Endpoints

All the available endpoints are generated in separate packages and assembled in the client. The `core` namespace is duplicated at the root of the client for convenient access.

Each endpoint follows a factory pattern which returns a pointer to a new instance each time.

[source,go]
-----
res, err := es.Search().Index("index_name").AllowPartialSearchResults(true).Do(context.Background())
-----

If parameters are needed for the specific endpoint you are using, those will be present as arguments in the same order as the API:

[source,go]
------------------------------------
es.Create("index_name", "doc_id").Do(context.Background())
------------------------------------

Otherwise, you can find them within the builder:

[source,go]
------------------------------------
es.Search().Index("index_name").Do(context.Background())
------------------------------------

Alternatively each endpoint can be instantiated directly from its package:

[source,go]
------------------------------------
transport, err := elastictransport.New(elastictransport.Config{})
res, err = search.New(transport).Do(context.Background())
------------------------------------

The `Do` method takes an optional `context`, runs the request through the transport and returns the results as well as an error.

For body-empty endpoints such as `core.Exists`, an additional method `IsSuccess` is available. As the `Do` method, it takes an optional `context`, drains and closes the body if needed, and returns a boolean alongside an error

[source,go]
-----
if exists, err := es.Core.Exists("index_name", "doc_id").IsSuccess(context.Background()); exists {
    // The document exists!
} else if err != nil {
    // An error occurred.
}
-----