Aspire.Elastic.Clients.Elasticsearch
9.0.0-preview.4.24511.1
Prefix Reserved
See the version list below for details.
dotnet add package Aspire.Elastic.Clients.Elasticsearch --version 9.0.0-preview.4.24511.1
NuGet\Install-Package Aspire.Elastic.Clients.Elasticsearch -Version 9.0.0-preview.4.24511.1
<PackageReference Include="Aspire.Elastic.Clients.Elasticsearch" Version="9.0.0-preview.4.24511.1" />
paket add Aspire.Elastic.Clients.Elasticsearch --version 9.0.0-preview.4.24511.1
#r "nuget: Aspire.Elastic.Clients.Elasticsearch, 9.0.0-preview.4.24511.1"
// Install Aspire.Elastic.Clients.Elasticsearch as a Cake Addin #addin nuget:?package=Aspire.Elastic.Clients.Elasticsearch&version=9.0.0-preview.4.24511.1&prerelease // Install Aspire.Elastic.Clients.Elasticsearch as a Cake Tool #tool nuget:?package=Aspire.Elastic.Clients.Elasticsearch&version=9.0.0-preview.4.24511.1&prerelease
Aspire.Elastic.Clients.Elasticsearch
Registers a ElasticsearchClient in the DI container for connecting to a Elasticsearch.
Getting started
Prerequisites
- Elasticsearch cluster.
- Endpoint URI string for accessing the Elasticsearch API endpoint or a CloudId and an ApiKey from Elastic Cloud
Install the package
Install the .NET Aspire Elasticsearch Client library with NuGet:
dotnet add package Aspire.Elastic.Clients.Elasticsearch
Usage example
In the Program.cs file of your project, call the AddElasticsearchClient
extension method to register a ElasticsearchClient
for use via the dependency injection container. The method takes a connection name parameter.
builder.AddElasticsearchClient("elasticsearch");
Configuration
The .NET Aspire Elasticsearch Client component provides multiple options to configure the server connection based on the requirements and conventions of your project.
Use a connection string
When using a connection string from the ConnectionStrings
configuration section, you can provide the name of the connection string when calling builder.AddElasticsearchClient()
:
builder.AddElasticsearchClient("elasticsearch");
And then the connection string will be retrieved from the ConnectionStrings
configuration section:
{
"ConnectionStrings": {
"elasticsearch": "http://elastic:password@localhost:27011"
}
}
Use configuration providers
The .NET Aspire Elasticsearch Client component supports Microsoft.Extensions.Configuration. It loads the ElasticClientsElasticsearchSettings
from configuration by using the Aspire:Elastic:Clients:Elasticsearch
key. Example appsettings.json
that configures some of the options:
{
"Aspire": {
"Elastic": {
"Clients": {
"Elasticsearch": {
"Endpoint": "http://elastic:password@localhost:27011"
}
}
}
}
}
Use inline delegates
Also you can pass the Action<ElasticClientsElasticsearchSettings> configureSettings
delegate to set up some or all the options inline, for example to set the API key from code:
builder.AddElasticsearchClient("elasticsearch", settings => settings.Endpoint = new Uri("http://elastic:password@localhost:27011"));
AppHost extensions
In your AppHost project, install the Aspire.Hosting.Elasticsearch
library with NuGet:
dotnet add package Aspire.Hosting.Elasticsearch
Then, in the Program.cs file of AppHost
, register a Elasticsearch cluster and consume the connection using the following methods:
var elasticsearch = builder.AddElasticsearch("elasticsearch");
var myService = builder.AddProject<Projects.MyService>()
.WithReference(elasticsearch);
The WithReference
method configures a connection in the MyService
project named elasticsearch
. In the Program.cs file of MyService
, the Elasticsearch connection can be consumed using:
builder.AddElasticsearchClient("elasticsearch");
Use a CloudId
and an ApiKey
with configuration providers
When using Elastic Cloud ,
you can provide the CloudId
and ApiKey
in Aspire:Elastic:Clients:Elasticsearch
section
when calling builder.AddElasticsearchClient()
.
Example appsettings.json that configures the options:
builder.AddElasticsearchClient("elasticsearch");
{
"Aspire": {
"Elastic": {
"Clients": {
"Elasticsearch": {
"ApiKey": "Valid ApiKey",
"CloudId": "Valid CloudId"
}
}
}
}
}
Use a CloudId
and an ApiKey
with inline delegates
builder.AddElasticsearchClient("elasticsearch",
settings => {
settings.CloudId = "Valid CloudId";
settings.ApiKey = "Valid ApiKey";
});
Additional documentation
- https://github.com/elastic/elasticsearch-net
- https://github.com/dotnet/aspire/tree/main/src/Components/README.md
Feedback & contributing
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net8.0
- Elastic.Clients.Elasticsearch (>= 8.15.8)
- Microsoft.Extensions.Configuration.Abstractions (>= 8.0.0)
- Microsoft.Extensions.Configuration.Binder (>= 8.0.2)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.10)
- Microsoft.Extensions.Hosting.Abstractions (>= 8.0.1)
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.2)
- Microsoft.Extensions.Options (>= 8.0.2)
- Microsoft.Extensions.Primitives (>= 8.0.0)
- OpenTelemetry.Extensions.Hosting (>= 1.9.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
9.0.0-preview.5.24551.3 | 69 | 11/12/2024 |
9.0.0-preview.4.24511.1 | 384 | 10/15/2024 |
8.2.2-preview.1.24521.5 | 60 | 10/24/2024 |
8.2.1-preview.1.24473.4 | 234 | 9/26/2024 |
8.2.0-preview.1.24428.5 | 527 | 8/29/2024 |
8.1.0-preview.1.24373.2 | 879 | 7/23/2024 |