
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
aspire.elastic.clients.elasticsearch
Advanced tools
Registers a ElasticsearchClient in the DI container for connecting to a Elasticsearch.
Install the .NET Aspire Elasticsearch Client library with NuGet:
dotnet add package Aspire.Elastic.Clients.Elasticsearch
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");
The .NET Aspire Elasticsearch Client component provides multiple options to configure the server connection based on the requirements and conventions of your project.
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"
}
}
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"
}
}
}
}
}
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"));
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");
CloudId
and an ApiKey
with configuration providersWhen 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"
}
}
}
}
}
CloudId
and an ApiKey
with inline delegatesbuilder.AddElasticsearchClient("elasticsearch",
settings => {
settings.CloudId = "Valid CloudId";
settings.ApiKey = "Valid ApiKey";
});
FAQs
Unknown package
We found that aspire.elastic.clients.elasticsearch demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.