﻿---
title: Set up Elasticsearch instrumentation
description: How to enable Elastic APM .NET Agent instrumentation of Elasticsearch queries for both the current and legacy .NET clients.
url: https://www.elastic.co/elastic/docs-builder/docs/3410/reference/apm/agents/dotnet/setup-elasticsearch
products:
  - APM .NET Agent
  - APM Agent
applies_to:
  - Serverless Observability projects: Generally available
  - Elastic Stack: Generally available
  - Application Performance Monitoring Agent for .NET: Generally available
---

# Set up Elasticsearch instrumentation
## Supported versions


| Package                                               | Supported versions |
|-------------------------------------------------------|--------------------|
| `Elastic.Clients.{{product.elasticsearch}}` (current) | ≥8.0.0 <10.0.0     |
| `{{product.elasticsearch}}.Net` (legacy)              | ≥7.6.0 <8.0.0      |
| `NEST` (legacy)                                       | ≥7.6.0 <8.0.0      |

For the full compatibility matrix including supported installation methods, refer to [Data access technologies](/elastic/docs-builder/docs/3410/reference/apm/agents/dotnet/supported-technologies#supported-data-access-technologies).

## Quick start

This page assumes the core agent is already set up. If not, see [Set up the APM .NET Agent](https://www.elastic.co/elastic/docs-builder/docs/3410/reference/apm/agents/dotnet/set-up-apm-net-agent) first.

### Current client

The currently supported Elasticsearch client for .NET ships in the [Elastic.Clients.Elasticsearch](https://www.nuget.org/packages/Elastic.Clients.Elasticsearch) NuGet package. This package and the underlying transport are instrumented with OpenTelemetry native APIs built into .NET. These will be picked up automatically when the [OpenTelemetry Bridge](/elastic/docs-builder/docs/3410/reference/apm/agents/dotnet/config-core#config-opentelemetry-bridge-enabled) feature is enabled. No additional Elastic APM .NET Agent package is required.

### Legacy clients

Add the [`Elastic.Apm.Elasticsearch`](https://www.nuget.org/packages/Elastic.Apm.Elasticsearch) NuGet package to your project:
```sh
dotnet add package Elastic.Apm.{{product.elasticsearch}}
```

Pass `{{product.elasticsearch}}DiagnosticsSubscriber` to the `AddElasticApm` method in case of ASP.NET Core as follows:
```csharp
using Elastic.Apm.Elasticsearch

app.Services.AddElasticApm(new {{product.elasticsearch}}DiagnosticsSubscriber());
```

or passing `{{product.elasticsearch}}DiagnosticsSubscriber` to the `Subscribe` method
```csharp
using Elastic.Apm;
using Elastic.Apm.Elasticsearch

Agent.Subscribe(new {{product.elasticsearch}}DiagnosticsSubscriber());
```

Instrumentation listens for activities raised by `{{product.elasticsearch}}.Net` and `Nest`, creating spans for executed requests.
<important>
  If you’re using `{{product.elasticsearch}}.Net` and `Nest` 7.10.1 or 7.11.0, upgrade to at least 7.11.1 which fixes a bug in span capturing.
</important>