Skip to content

wioniqle-q/elasticsearch-automapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 

Repository files navigation

Elasticsearch Auto Mapper

Description

That makes you can easily auto-map for elasticsearch types.

Versions

  • Elastic.Clients.Elasticseach => 8.15.8
  • .NET Version => 9.0.0-rc.1

Example of the code:

var settings = new ElasticsearchClientSettings(new Uri(""))
            .Authentication(new BasicAuthentication("", ""))
            .PrettyJson()
            .CertificateFingerprint("")
            .DisableDirectStreaming();

var IndexName = "";
var client = new ElasticsearchClient(settings);

await CreateIndexWithMapping(client);

private static async Task CreateIndexWithMapping(ElasticsearchClient client)
{
    var exists = await client.Indices.ExistsAsync(IndexName);
    if (exists.Exists)
        return;
    
    var createIndex = await client.Indices.CreateAsync(IndexName, i =>
    {
        i.Mappings(m =>
        {
            // The model you want to map can be set to T.
            m.Properties(ElasticAutoMapper.MapToElasticIndex<T>()); 
        });
    });
    
    Console.WriteLine(createIndex.IsValidResponse
        ? "Index created successfully with mapping."
        : $"Failed to create index: {createIndex.DebugInformation}");
 }

Custom Attributes:

[ElasticsearchCustomMapping] => You can make a custom maps for custom wishes.
[ElasticsearchIgnore] => Using this attribute you can write to models that you do not want to be processed.
[ElasticsearchPropertyName] => Using this attribute you can set the name of the object in your model without SneakCase.
[ElasticsearchStringMapping] => Using this attribute you can say that the object in your model is a KeywordProperty.

Releases

No releases published

Packages

No packages published

Languages