Loading

Elastic.Mapping

Describe your Elasticsearch mapping with C# attributes. A source generator turns those declarations into component template JSON at compile time, so you never write mapping JSON by hand.

public class Product
{
    [Id]
    [Keyword]
    public string Sku { get; set; }

    [Text(Analyzer = "standard")]
    public string Name { get; set; }

    [Keyword]
    public string Category { get; set; }
}

[ElasticsearchMappingContext]
[Index<Product>(Name = "products")]
public static partial class MyContext;
		

From this declaration, the source generator produces all the JSON, hashes, and metadata that Elastic.Ingest.Elasticsearch needs to create templates, send bulk requests, and manage indices.

dotnet add package Elastic.Ingest.Elasticsearch
		

This pulls in Elastic.Mapping (with the bundled source generator) and Elastic.Channels as transitive dependencies.

Document class+ field attributes Source generator Context class+ Index, DataStream ConfigureAnalysisConfigureMappings Mappings JSON Settings JSON Accessor delegates(GetId, GetTimestamp) Content hash Component template Bulk operations Change detection

The generator:

  • Finds classes marked with [ElasticsearchMappingContext]
  • Reads each [Index<T>], [DataStream<T>], or [WiredStream<T>] registration
  • Walks the document type's properties to infer Elasticsearch field types
  • Parses any ConfigureAnalysis / ConfigureMappings methods
  • Emits a partial context class with everything the ingest channel needs