Skip to content
DocsTry Aspire
DocsTry

ElasticsearchBuilderExtensions Methods

ClassMethods3 members
Provides extension methods for adding Elasticsearch resources to the application model.
AddElasticsearch(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, int?)Section titled AddElasticsearch(IDistributedApplicationBuilder, string, IResourceBuilder<ParameterResource>, int?)extensionIResourceBuilder<ElasticsearchResource>
Adds an Elasticsearch container resource to the application model.
public static class ElasticsearchBuilderExtensions
{
public static IResourceBuilder<ElasticsearchResource> AddElasticsearch(
this IDistributedApplicationBuilder builder,
string name,
IResourceBuilder<ParameterResource>? password = null,
int? port = null)
{
// ...
}
}
builderIDistributedApplicationBuilderThe Hosting.IDistributedApplicationBuilder.
namestringThe name of the resource. This name will be used as the connection string name when referenced in a dependency.
passwordIResourceBuilder<ParameterResource>optionalThe parameter used to provide the superuser password for the elasticsearch. If null a random password will be generated.
portint?optionalThe host port to bind the underlying container to.
IResourceBuilder<ElasticsearchResource>A reference to the ApplicationModel.IResourceBuilder`1.
This version of the package defaults to the tag of the container image. 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();
WithDataBindMount(IResourceBuilder<ElasticsearchResource>, string)Section titled WithDataBindMount(IResourceBuilder<ElasticsearchResource>, string)extensionIResourceBuilder<ElasticsearchResource>
Adds a bind mount for the data folder to a Elasticsearch container resource.
public static class ElasticsearchBuilderExtensions
{
public static IResourceBuilder<ElasticsearchResource> WithDataBindMount(
this IResourceBuilder<ElasticsearchResource> builder,
string source)
{
// ...
}
}
builderIResourceBuilder<ElasticsearchResource>The resource builder.
sourcestringThe source directory on the host to mount into the container.
IResourceBuilder<ElasticsearchResource>The ApplicationModel.IResourceBuilder`1.
Add an Elasticsearch container to the application model and reference it in a .NET project. Additionally, in this example a bind mount is added to the container to allow data to be persisted across container restarts.
var builder = DistributedApplication.CreateBuilder(args);
var elasticsearch = builder.AddElasticsearch("elasticsearch")
.WithDataBindMount("./data/elasticsearch/data");
var api = builder.AddProject<Projects.Api>("api")
.WithReference(elasticsearch);
builder.Build().Run();
WithDataVolume(IResourceBuilder<ElasticsearchResource>, string?)Section titled WithDataVolume(IResourceBuilder<ElasticsearchResource>, string?)extensionIResourceBuilder<ElasticsearchResource>
Adds a named volume for the data folder to a Elasticsearch container resource.
public static class ElasticsearchBuilderExtensions
{
public static IResourceBuilder<ElasticsearchResource> WithDataVolume(
this IResourceBuilder<ElasticsearchResource> builder,
string? name = null)
{
// ...
}
}
builderIResourceBuilder<ElasticsearchResource>The resource builder.
namestring?optionalThe name of the volume. Defaults to an auto-generated name based on the application and resource names.
IResourceBuilder<ElasticsearchResource>The ApplicationModel.IResourceBuilder`1.
Add an Elasticsearch container to the application model and reference it in a .NET project. Additionally, in this example a data volume is added to the container to allow data to be persisted across container restarts.
var builder = DistributedApplication.CreateBuilder(args);
var elasticsearch = builder.AddElasticsearch("elasticsearch")
.WithDataVolume();
var api = builder.AddProject<Projects.Api>("api")
.WithReference(elasticsearch);
builder.Build().Run();