You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

aspire.elastic.clients.elasticsearch

Package Overview
Dependencies
Maintainers
0
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

aspire.elastic.clients.elasticsearch

9.2.1-preview.1.25222.1
nugetNuGet
Version published
Maintainers
0
Created
Source

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

Feedback & contributing

https://github.com/dotnet/aspire

Keywords

aspire

FAQs

Package last updated on 24 Apr 2025

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.