Interface IElasticIndexConfiguration<TSelf>
- Namespace
- Excalibur.Data.ElasticSearch
- Assembly
- Excalibur.Data.ElasticSearch.dll
Configures the Elasticsearch index mapping for a document type.
public interface IElasticIndexConfiguration<TSelf> where TSelf : class
Type Parameters
TSelfThe document type that this configuration applies to.
Examples
public sealed class OrderSearchProjection : IElasticIndexConfiguration<OrderSearchProjection>
{
public Guid OrderId { get; set; }
public string CustomerName { get; set; }
public string Status { get; set; }
public decimal TotalAmount { get; set; }
public DateTime OrderDate { get; set; }
public List<string> Tags { get; set; }
public static Properties ConfigureIndex()
{
return new Properties
{
{ "orderId", new KeywordProperty() },
{ "customerName", new TextProperty
{
Fields = new Properties { { "keyword", new KeywordProperty { IgnoreAbove = 256 } } }
}
},
{ "status", new KeywordProperty() },
{ "totalAmount", new DoubleNumberProperty() },
{ "orderDate", new DateProperty() },
{ "tags", new KeywordProperty() }
};
}
}
Remarks
Implement this interface on your projection or document class to provide
explicit field mappings instead of relying on Elasticsearch dynamic mapping.
This follows the same pattern as EF Core's IEntityTypeConfiguration<T>.
When implemented, both ElasticSearchProjectionStore<T> and
ElasticRepositoryBase<T> will use these mappings during index creation.
Three-tier mapping strategy:
- Explicit (best): Implement this interface for full control over field types, analyzers, and index settings.
- Inferred (good default): When this interface is not implemented, the framework reflects over public properties and maps them to appropriate Elasticsearch types (keyword for strings/Guids, long/double for numerics, date for DateTime, etc.).
-
Dynamic (fallback): If both explicit and inferred mapping are bypassed,
Elasticsearch uses its own dynamic mapping rules, which can produce incorrect
types (e.g., mapping a numeric string as
longinstead ofkeyword).
Methods
ConfigureIndex()
Returns the Elasticsearch index field mappings for this document type.
public static abstract Properties ConfigureIndex()
Returns
- Properties
An Elasticsearch Elastic.Clients.Elasticsearch.Mapping.Properties dictionary mapping JSON field names to their property types. Use Elasticsearch mapping types such as: Elastic.Clients.Elasticsearch.Mapping.KeywordProperty for exact-match strings (IDs, codes, statuses), Elastic.Clients.Elasticsearch.Mapping.TextProperty for full-text searchable strings, Elastic.Clients.Elasticsearch.Mapping.LongNumberProperty or Elastic.Clients.Elasticsearch.Mapping.DoubleNumberProperty for numeric fields, Elastic.Clients.Elasticsearch.Mapping.DateProperty for date/time fields, Elastic.Clients.Elasticsearch.Mapping.BooleanProperty for boolean fields, Elastic.Clients.Elasticsearch.Mapping.NestedProperty for complex nested objects that need independent querying.