Class ElasticSearchProjectionIndexConvention
- Namespace
- Excalibur.Data.ElasticSearch.Projections
- Assembly
- Excalibur.Data.ElasticSearch.dll
Resolves ElasticSearch index names for projection stores using the configured naming convention.
public static class ElasticSearchProjectionIndexConvention
- Inheritance
-
ElasticSearchProjectionIndexConvention
- Inherited Members
Examples
// In a custom repository that needs the same index as IProjectionStore<OrderListItem>
public class OrderSearchRepository : ElasticRepositoryBase<OrderListItem>
{
public OrderSearchRepository(
ElasticsearchClient client,
IOptionsMonitor<ElasticSearchProjectionStoreOptions> optionsMonitor)
: base(client, ElasticSearchProjectionIndexConvention.GetIndexName<OrderListItem>(
optionsMonitor.Get(ElasticSearchProjectionIndexConvention.GetOptionsName<OrderListItem>())))
{
}
}
Remarks
Use this class when building custom repositories (e.g. extending ElasticRepositoryBase<TDocument>)
that need to target the same index as an IProjectionStore<T>. This ensures both the projection
store and your custom repository resolve to the same index name from a single source of truth.
The naming convention is: {IndexPrefix}-{IndexName ?? projectionTypeName}.
When IndexPrefix is empty/whitespace, the prefix is omitted.
When IndexName is set, it replaces the projection type name.
Methods
GetIndexName(ElasticSearchProjectionStoreOptions, string)
Resolves the ElasticSearch index name for a projection type name using the configured options.
public static string GetIndexName(ElasticSearchProjectionStoreOptions options, string projectionTypeName)
Parameters
optionsElasticSearchProjectionStoreOptionsThe projection store options containing prefix and index name configuration.
projectionTypeNamestringThe projection type name (e.g.
"OrderSummary").
Returns
- string
The resolved index name (e.g.
"projections-ordersummary").
Remarks
This overload resolves the first generation's index. A declared generation lives on the projection TYPE, which a name cannot carry, so use the overload taking a Type wherever one is in hand.
GetIndexName(ElasticSearchProjectionStoreOptions, Type)
Resolves the ElasticSearch index name for a projection type using the configured options.
public static string GetIndexName(ElasticSearchProjectionStoreOptions options, Type projectionType)
Parameters
optionsElasticSearchProjectionStoreOptionsThe projection store options containing prefix and index name configuration.
projectionTypeTypeThe projection type whose index name is resolved.
Returns
- string
The resolved index name (e.g.
"projections-ordersummary-v2").
Remarks
Prefer this over the overload taking a type NAME. A generation is declared on the type, so a caller holding only a name cannot resolve one and will address the first generation's index whatever the type declares.
The generation lands as a trailing -v{n} segment, the convention side-by-side index
workflows already use, and it appears only from the second generation onward: a projection
declaring no generation, or the first, resolves to exactly the name it resolves to without this
feature.
GetIndexName<TProjection>(ElasticSearchProjectionStoreOptions)
Resolves the ElasticSearch index name for a projection type using the configured options.
public static string GetIndexName<TProjection>(ElasticSearchProjectionStoreOptions options) where TProjection : class
Parameters
optionsElasticSearchProjectionStoreOptionsThe projection store options containing prefix and index name configuration.
Returns
- string
The resolved index name (e.g.
"development-projections-ordersummary").
Type Parameters
TProjectionThe projection type. The lowercased type name is used when IndexName is not set.
Remarks
The projection's declared generation participates in the name, so a bump addresses a new index.
GetOptionsName(Type)
The name of the options instance a projection's store settings live under.
public static string GetOptionsName(Type projectionType)
Parameters
projectionTypeTypeThe projection type.
Returns
- string
The options name — the projection's full type name, falling back to its simple name.
Remarks
The overload for a caller holding a Type rather than a compile-time generic — the rebuild path, which is handed the projection type. It is the SAME derivation the generic overload performs, which is the point: a second derivation of the bucket name is a second chance for one to drift, and a caller that derived it from the SIMPLE name read an unconfigured default bucket and resolved a different index than the store writes to.
GetOptionsName<TProjection>()
The name of the options instance a projection's store settings live under.
public static string GetOptionsName<TProjection>() where TProjection : class
Returns
- string
The options name — the projection's full type name, falling back to its simple name.
Type Parameters
TProjectionThe projection type.
Remarks
Use this rather than writing nameof(MyProjection) at the call site. It was derived
independently in three places — the store, the registration, and every consumer repository that
reads the same bucket — and three derivations of one fact are three chances for one to drift.
The full type name isolates settings for projections with the same simple name in different namespaces. This bucket identity is separate from index naming, which defaults to the SIMPLE name and therefore does collide for such a pair — so configure distinct index names for those projections when they share a cluster. Failing to is refused at start-up rather than silently pointing two read models at one index.