共用方式為


ElasticsearchBuilderExtensions.AddElasticsearch Method

Definition

Adds an Elasticsearch container resource to the application model.

public static Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ElasticsearchResource> AddElasticsearch (this Aspire.Hosting.IDistributedApplicationBuilder builder, string name, Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ParameterResource>? password = default, int? port = default);
static member AddElasticsearch : Aspire.Hosting.IDistributedApplicationBuilder * string * Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ParameterResource> * Nullable<int> -> Aspire.Hosting.ApplicationModel.IResourceBuilder<Aspire.Hosting.ApplicationModel.ElasticsearchResource>
<Extension()>
Public Function AddElasticsearch (builder As IDistributedApplicationBuilder, name As String, Optional password As IResourceBuilder(Of ParameterResource) = Nothing, Optional port As Nullable(Of Integer) = Nothing) As IResourceBuilder(Of ElasticsearchResource)

Parameters

name
String

The name of the resource. This name will be used as the connection string name when referenced in a dependency.

password
IResourceBuilder<ParameterResource>

The parameter used to provide the superuser password for the elasticsearch. If null a random password will be generated.

port
Nullable<Int32>

The host port to bind the underlying container to.

Returns

A reference to the IResourceBuilder<T>.

Examples

Add an Elasticsearch container to the application model and reference it in a .NET project.

var builder = DistributedApplication.CreateBuilder(args);

var elasticsearch = builder.AddElasticsearch("elasticsearch");
var api = builder.AddProject<Projects.Api>("api")
  .WithReference(elasticsearch);

builder.Build().Run();

Remarks

This version of the package defaults to the tag of the container image.

Applies to