Loading

Strongly-typed analysis names

When you define custom analyzers, tokenizers, or filters via ConfigureAnalysis, the source generator emits accessor classes that expose those names as properties. This gives you compile-time verification instead of runtime failures from typos.

A typo in an analyzer reference silently produces a broken mapping:

// No compile-time check. Fails at index time.
[Text(Analyzer = "product_naem_analyzer")]
public string Name { get; set; }
		
  1. typo!

The generator emits a static class with properties for each custom analysis component:

// Generated: ProductAnalysis
public static class ProductAnalysis
{
    public sealed class AnalyzersAccessor : Elastic.Mapping.Analysis.AnalyzersAccessor
    {
        public string ProductNameAnalyzer => "product_name_analyzer";
    }

    public sealed class NormalizersAccessor : Elastic.Mapping.Analysis.NormalizersAccessor
    {
        public string LowercaseNormalizer => "lowercase_normalizer";
    }

    public static readonly AnalyzersAccessor Analyzers = new();
    public static readonly TokenizersAccessor Tokenizers = new();
    public static readonly TokenFiltersAccessor TokenFilters = new();
    public static readonly CharFiltersAccessor CharFilters = new();
    public static readonly NormalizersAccessor Normalizers = new();
}
		

Reference analysis components through the generated accessor:

// Compile-time verified. A typo here is a build error.
mappings.Name(f => f.Analyzer(ProductAnalysis.Analyzers.ProductNameAnalyzer));

// Built-in names are also available through the same accessor
mappings.Title(f => f.Analyzer(ProductAnalysis.Analyzers.Standard));

// Language analyzers
mappings.Body(f => f.Analyzer(ProductAnalysis.Analyzers.Language.English));
		

Each accessor class inherits from a base class that exposes all built-in Elasticsearch names. Custom names are added as additional properties.

Component names are converted from snake_case to PascalCase:

Analysis component name Generated property name
product_name_analyzer ProductNameAnalyzer
keyword_normalizer KeywordNormalizer
starts_with_tokenizer StartsWithTokenizer
english_stop EnglishStop

Every generated accessor inherits built-in Elasticsearch names alongside your custom ones:

// Custom analyzer
ProductAnalysis.Analyzers.ProductNameAnalyzer   // "product_name_analyzer"

// Built-in analyzer (inherited from base)
ProductAnalysis.Analyzers.Standard              // "standard"
ProductAnalysis.Analyzers.Whitespace            // "whitespace"
ProductAnalysis.Analyzers.Language.English       // "english"

// Built-in token filters (inherited from base)
ProductAnalysis.TokenFilters.Lowercase          // "lowercase"
ProductAnalysis.TokenFilters.AsciiFolding       // "asciifolding"
		

One accessor is your single source of truth for all analysis component names.