Skip to content
Docs Try Aspire

ElasticsearchBuilderExtensions Methods

Class Methods 3 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?) extension IResourceBuilder<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)
{
// ...
}
}
builder IDistributedApplicationBuilder The Hosting.IDistributedApplicationBuilder.
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> optional The parameter used to provide the superuser password for the elasticsearch. If null a random password will be generated.
port int? optional The 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) extension IResourceBuilder<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)
{
// ...
}
}
builder IResourceBuilder<ElasticsearchResource> The resource builder.
source string The 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?) extension IResourceBuilder<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)
{
// ...
}
}
builder IResourceBuilder<ElasticsearchResource> The resource builder.
name string? optional The 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();