This directory contains examples and recipes for the Elasticsearch Go client.
The configuration.go and customization.go files contain information for configuring and customizing the client transport.
The totyped.go file demonstrates incremental migration from the functional (low-level) API to the typed API using elasticsearch.NewTypedFrom(c). The returned *TypedClient shares the source client's transport and configuration, so existing call sites keep working while new code can use the typed builder API.
The typed_endpoint.go file shows the lightest-weight migration step: using a single typed endpoint (for example typedapi/core/search) directly against the existing functional *elasticsearch.Client, without constructing a full *TypedClient or calling NewTypedFrom. Every typed endpoint package exports a New(elastictransport.Interface) constructor, and the functional client satisfies that interface via its embedded BaseClient.Perform. The same file also shows elasticsearch.NewBase(...), which returns a raw *BaseClient for fresh code that only ever needs a handful of typed endpoints, skipping both the esapi tree and the typedapi MethodAPI tree.
The logging directory contains examples for using the default loggers and implementing a custom logger.
The bulk directory contains a comprehensive example of using the Bulk API.
The search directory contains examples for using the Search API
with the typed client, showing both the esdsl query builders and raw types.* structs.
The msearchtemplate directory contains examples for using the MSearchTemplate API
with both esapi and typedapi.
The encoding directory contains examples of using third-party packages
and client helper methods for a more efficient encoding and decoding of the request and response bodies.
The fasthttp directory contains a demonstration of replacing the default client transport with an HTTP client from the github.com/valyala/fasthttp package.
The instrumentation directory contains recipes for instrumenting the client: exposing client metrics via expvar, and enabling the built-in OpenTelemetry integration via elasticsearch.NewOpenTelemetryInstrumentation. For an interceptor-based OpenTelemetry alternative see interceptor/cmd/custom_observability.
The interceptor directory contains examples of using Interceptors to modify HTTP requests before they are sent to Elasticsearch, including dynamic auth, per-request auth override, custom auth (Kerberos/SPNEGO), and custom observability.
The extension directory contains an example of extending the client APIs, for example
to support custom endpoints installed by a plugin.
The cloudfunction directory contains a simple web service for checking Elasticsearch cluster status.
The xkcdsearch directory contains a command-line utility for indexing and searching an archive of xkcd.com artworks.