Types and relations inferenceedit

TypeName defaultedit

Type names are resolved by lowercasing the type name

var settings = new ConnectionSettings();
var resolver = new TypeNameResolver(settings);
var index = resolver.Resolve<Project>();
index.Should().Be("project");

Default Type Nameedit

With Elasticsearch 6.x you can only have a single type per index and in the long run types will be phased out. The need to tag types is no longer necessary so in many cases it makes sense to use a single fixed type.

var settings = new ConnectionSettings().DefaultTypeName("doc");
var resolver = new TypeNameResolver(settings);
var index = resolver.Resolve<Project>();
index.Should().Be("doc");

Override tye name infereredit

You can provide a delegate to override the default type name inferrer for types

var settings = new ConnectionSettings()
    .DefaultTypeNameInferrer(t=>t.Name.ToLower() + "-suffix");
var resolver = new TypeNameResolver(settings);
var type = resolver.Resolve<Project>();
type.Should().Be("project-suffix");

Relation namesedit

Prior to Elasticsearch 6.x you could have multiple types per index. They acted as a discrimatory column but were often confused with tables. The fact that the mapping API’s treated them as seperate entities did not help.

The general guideline has always been to use a single type per index. Starting from 6.x this is also enforced. Some features still need to store multiple types in a single index such as Parent/Child join relations.

Both Parent and Child will need to have resolve to the same typename to be indexed into the same index.

Therefore in 6.x we need a different type that translates a CLR type to a join relation. This can be configured seperately using .RelationName()

var settings = new ConnectionSettings()
    .DefaultMappingFor<CommitActivity>(m => m
        .IndexName("projects-and-commits")
        .TypeName("doc")
        .RelationName("commits")
    )
    .DefaultMappingFor<Project>(m => m
        .IndexName("projects-and-commits")
        .TypeName("doc")
        .RelationName("projects")
    );

var resolver = new RelationNameResolver(settings);
var relation = resolver.Resolve<Project>();
relation.Should().Be("projects");

relation = resolver.Resolve<CommitActivity>();
relation.Should().Be("commits");

var settings = new ConnectionSettings()
    .DefaultMappingFor<Project>(m => m
        .IndexName("projects-and-commits")
        .TypeName("doc")
    );

var resolver = new RelationNameResolver(settings);
var relation = resolver.Resolve<Project>();
relation.Should().Be("project");