Path: redb-route/redb.Route.Elasticsearch/ElasticsearchEndpointOptions.cs
Snapshot: redb-route, development snapshot 2026-12-06. This is the development state of the public mirrors; it may differ from the published packages.
License: Apache-2.0. Repository: https://github.com/redbase-app/redb-route
Page: https://redbase.app/src/dev-2026-12-06/redb-route/redb.Route.Elasticsearch/ElasticsearchEndpointOptions.cs
----
using redb.Route.Core;
namespace redb.Route.Elasticsearch;
///
/// Endpoint options for Elasticsearch transport. All properties are auto-bound from URI query parameters.
///
/// URI format: elasticsearch://index-name?nodes=http://localhost:9200
///
///
/// Short alias: es://index-name?nodes=http://localhost:9200
///
///
/// For producer operations: es:Search:index-name?nodes=http://localhost:9200&query={"match_all":{}}
///
///
public class ElasticsearchEndpointOptions : EndpointOptions
{
// ═══════════════════════════════════════════════════════════════════
// CONNECTION
// ═══════════════════════════════════════════════════════════════════
///
/// Comma-separated list of Elasticsearch node URIs.
/// Example: http://localhost:9200 or http://node1:9200,http://node2:9200.
///
public string Nodes { get; set; } = "http://localhost:9200";
/// API key authentication (base64-encoded).
[Sensitive]
public string ApiKey { get; set; } = "";
/// Basic auth username.
public string Username { get; set; } = "";
/// Basic auth password.
[Sensitive]
public string Password { get; set; } = "";
/// SHA-256 certificate fingerprint for TLS verification.
public string CertificateFingerprint { get; set; } = "";
///
/// Named connection factory reference. If set, looks up an
/// from the DI registry by this name to build the client.
///
[RegistryReference(typeof(ElasticsearchConnectionFactory))]
public string ConnectionFactory { get; set; } = "";
/// Enable debug mode — log raw requests/responses. (default: false)
public bool EnableDebugMode { get; set; }
// ═══════════════════════════════════════════════════════════════════
// TIMEOUTS / RESILIENCE
// ═══════════════════════════════════════════════════════════════════
/// Request timeout in milliseconds. (default: 30000)
public int RequestTimeout { get; set; } = 30_000;
/// Ping timeout in milliseconds. (default: 2000)
public int PingTimeout { get; set; } = 2000;
/// Dead node backoff timeout in milliseconds. (default: 60000)
public int DeadTimeout { get; set; } = 60_000;
/// Max dead node backoff timeout in milliseconds. (default: 600000)
public int MaxDeadTimeout { get; set; } = 600_000;
/// Maximum number of retries per request. (default: 3)
public int MaxRetries { get; set; } = 3;
// ═══════════════════════════════════════════════════════════════════
// COMMON
// ═══════════════════════════════════════════════════════════════════
///
/// Producer operation type. Parsed from URI path prefix or query param.
/// (default: )
///
public ElasticsearchOperationType Operation { get; set; } = ElasticsearchOperationType.Index;
/// Ingest pipeline name to apply on index/bulk operations.
public string Pipeline { get; set; } = "";
/// Custom routing value.
public string Routing { get; set; } = "";
///
/// Dynamic document ID expression. Supports ${header.redbEs.DocumentId} etc.
/// If not set, Elasticsearch auto-generates an ID (for Index) or the header is used.
///
public DynamicValue? DocumentId { get; set; }
/// Refresh policy: "true", "false", or "wait_for". (default: "false")
public string Refresh { get; set; } = "";
// ═══════════════════════════════════════════════════════════════════
// BULK SETTINGS
// ═══════════════════════════════════════════════════════════════════
/// Max documents per bulk request. (default: 100)
public int BulkSize { get; set; } = 100;
// ═══════════════════════════════════════════════════════════════════
// CONSUMER (polling search)
// ═══════════════════════════════════════════════════════════════════
/// Polling delay between search cycles in milliseconds. (default: 5000)
public int Delay { get; set; } = 5000;
/// Initial delay before first poll in milliseconds. (default: 1000)
public int InitialDelay { get; set; } = 1000;
///
/// JSON query DSL string. If empty, uses match_all.
/// Example: {"term":{"status":"active"}}
///
public string Query { get; set; } = "";
/// Number of hits per search page. (default: 100, max 10000)
public int Size { get; set; } = 100;
///
/// Scroll timeout for Scroll API (e.g. "1m", "5m"). If empty, uses search_after pagination.
///
public string ScrollTimeout { get; set; } = "";
///
/// Sort field(s) for ordering. Format: timestamp:desc,_id:asc.
/// Required for search_after pagination. If empty, defaults to _doc:asc.
///
public string Sort { get; set; } = "";
/// Delete document after successful processing. (default: false)
public bool DeleteAfterRead { get; set; }
/// Track total hit count. (default: true)
public bool TrackTotalHits { get; set; } = true;
///
/// Comma-separated list of fields to include in _source.
/// Example: title,author,timestamp
///
public string SourceIncludes { get; set; } = "";
///
/// Comma-separated list of fields to exclude from _source.
/// Example: large_blob,internal_field
///
public string SourceExcludes { get; set; } = "";
// ═══════════════════════════════════════════════════════════════════
// VALIDATION
// ═══════════════════════════════════════════════════════════════════
///
public override void Validate()
{
if (string.IsNullOrWhiteSpace(Nodes) && string.IsNullOrWhiteSpace(ConnectionFactory))
throw new ArgumentOutOfRangeException(nameof(Nodes), "Nodes or ConnectionFactory is required");
if (Delay < 100)
throw new ArgumentOutOfRangeException(nameof(Delay), "Delay must be >= 100ms");
if (Size < 1 || Size > 10_000)
throw new ArgumentOutOfRangeException(nameof(Size), "Size must be 1-10000");
if (BulkSize < 1)
throw new ArgumentOutOfRangeException(nameof(BulkSize), "BulkSize must be >= 1");
if (RequestTimeout < 1000)
throw new ArgumentOutOfRangeException(nameof(RequestTimeout), "RequestTimeout must be >= 1000ms");
if (MaxRetries < 0)
throw new ArgumentOutOfRangeException(nameof(MaxRetries), "MaxRetries must be >= 0");
}
}