Support of Elasticsearch for .NET

CAST supports Eleasticsearch via its com.castsoftware.nosqldotnetexternal link extension. Details about how this support is provided for .NET source code is discussed below.

Supported Client Libraries

Library Version

Supported

Elasticsearch.NET 7.x

NEST 7.x

Supported Operations

Operation Scenario Methods Supported
Insert Elasticsearch.Net

Elasticsearch.Net.ElasticLowLevelClient.Index

Elasticsearch.Net.ElasticLowLevelClient.IndexAsync

Elasticsearch.Net.ElasticLowLevelClient.Bulk

Elasticsearch.Net.ElasticLowLevelClient.BulkAsync

Elasticsearch.Net.ElasticLowLevelClient.Index

Elasticsearch.Net.ElasticLowLevelClient.IndexAsync

Elasticsearch.Net.ElasticLowLevelClient.IndexUsingType

Elasticsearch.Net.ElasticLowLevelClient.IndexUsingTypeAsync

Insert NEST

Nest.ElasticClient.Index

Nest.ElasticClient.IndexAsync

Nest.ElasticClient.IndexDocument

Nest.ElasticClient.IndexDocumentAsync

Nest.ElasticClient.Bulk

Nest.ElasticClient.BulkAsync

Nest.ElasticClient.Index

Nest.ElasticClient.IndexAsync

Nest.ElasticClient.IndexDocument

Nest.ElasticClient.IndexDocumentAsync

Nest.ElasticClient.Create

Nest.ElasticClient.CreateAsync

Nest.ElasticClient.CreateUsingType

Nest.ElasticClient.CreateUsingTypeAsync

Update Elasticsearch.Net

Elasticsearch.Net.ElasticLowLevelClient.Update

Elasticsearch.Net.ElasticLowLevelClient.UpdateAsync

Elasticsearch.Net.ElasticLowLevelClient.UpdateByQuery

Elasticsearch.Net.ElasticLowLevelClient.UpdateByQueryAsync

Elasticsearch.Net.ElasticLowLevelClient.Update

Elasticsearch.Net.ElasticLowLevelClient.UpdateAsync

Elasticsearch.Net.ElasticLowLevelClient.UpdateByQuery

Elasticsearch.Net.ElasticLowLevelClient.UpdateByQueryAsync

Update NEST

Nest.ElasticClient.Update

Nest.ElasticClient.UpdateAsync

Nest.ElasticClient.UpdateByQuery

Nest.ElasticClient.UpdateByQueryAsync

Nest.ElasticClient.Update

Nest.ElasticClient.UpdateAsync

Nest.ElasticClient.UpdateByQuery

Nest.ElasticClient.UpdateByQueryAsync

Select Elasticsearch.Net

Elasticsearch.Net.ElasticLowLevelClient.Search

Elasticsearch.Net.ElasticLowLevelClient.SearchAsync

Elasticsearch.Net.ElasticLowLevelClient.DocumentExists

Elasticsearch.Net.ElasticLowLevelClient.DocumentExistsAsync

Elasticsearch.Net.ElasticLowLevelClient.Explain

Elasticsearch.Net.ElasticLowLevelClient.ExplainAsync

Elasticsearch.Net.ElasticLowLevelClient.Count

Elasticsearch.Net.ElasticLowLevelClient.CountAsync

Elasticsearch.Net.ElasticLowLevelClient.CountUsingType

Elasticsearch.Net.ElasticLowLevelClient.CountUsingTypeAsync

Elasticsearch.Net.ElasticLowLevelClient.DocumentExists

Elasticsearch.Net.ElasticLowLevelClient.DocumentExistsAsync

Elasticsearch.Net.ElasticLowLevelClient.Explain

Elasticsearch.Net.ElasticLowLevelClient.ExplainAsync

Elasticsearch.Net.ElasticLowLevelClient.Get

Elasticsearch.Net.ElasticLowLevelClient.GetAsync

Elasticsearch.Net.ElasticLowLevelClient.MultiGet

Elasticsearch.Net.ElasticLowLevelClient.MultiGetAsync

Elasticsearch.Net.ElasticLowLevelClient.MultiGetUsingType

Elasticsearch.Net.ElasticLowLevelClient.MultiGetUsingTypeAsync

Elasticsearch.Net.ElasticLowLevelClient.MultiTermVectors

Elasticsearch.Net.ElasticLowLevelClient.MultiTermVectorsAsync

Elasticsearch.Net.ElasticLowLevelClient.MultiTermVectorsUsingType

Elasticsearch.Net.ElasticLowLevelClient.MultiTermVectorsUsingTypeAsync

Elasticsearch.Net.ElasticLowLevelClient.Search

Elasticsearch.Net.ElasticLowLevelClient.SearchAsync

Elasticsearch.Net.ElasticLowLevelClient.SearchMvt

Elasticsearch.Net.ElasticLowLevelClient.SearchMvtAsync

Elasticsearch.Net.ElasticLowLevelClient.Source

Elasticsearch.Net.ElasticLowLevelClient.SourceAsync

Elasticsearch.Net.ElasticLowLevelClient.SourceExists

Elasticsearch.Net.ElasticLowLevelClient.SourceExistsAsync

Elasticsearch.Net.ElasticLowLevelClient.SourceExistsUsingType

Elasticsearch.Net.ElasticLowLevelClient.SourceExistsUsingTypeAsync

Elasticsearch.Net.ElasticLowLevelClient.SourceUsingType

Elasticsearch.Net.ElasticLowLevelClient.SourceUsingTypeAsync

Elasticsearch.Net.ElasticLowLevelClient.TermVectors

Elasticsearch.Net.ElasticLowLevelClient.TermVectorsAsync

Elasticsearch.Net.ElasticLowLevelClient.TermVectorsUsingType

Elasticsearch.Net.ElasticLowLevelClient.TermVectorsUsingTypeAsync

Select NEST

Nest.ElasticClient.Search

Nest.ElasticClient.SearchAsync

Nest.ElasticClient.DocumentExists

Nest.ElasticClient.DocumentExistsAsync

Nest.ElasticClient.Explain

Nest.ElasticClient.ExplainAsync

Nest.ElasticClient.Get

Nest.ElasticClient.GetAsync

Nest.ElasticClient.Count

Nest.ElasticClient.CountAsync

Nest.ElasticClient.DocumentExists

Nest.ElasticClient.DocumentExistsAsync

Nest.ElasticClient.Explain

Nest.ElasticClient.ExplainAsync

Nest.ElasticClient.Get

Nest.ElasticClient.GetAsync

Nest.ElasticClient.MultiGet

Nest.ElasticClient.MultiGetAsync

Nest.ElasticClient.MultiSearch

Nest.ElasticClient.MultiSearchAsync

Nest.ElasticClient.MultiSearchTemplate

Nest.ElasticClient.MultiSearchTemplateAsync

Nest.ElasticClient.MultiTermVectors

Nest.ElasticClient.MultiTermVectorsAsync

Nest.ElasticClient.Source

Nest.ElasticClient.SourceAsync

Nest.ElasticClient.SourceExists

Nest.ElasticClient.SourceExistsAsync

Nest.ElasticClient.TermVectors

Nest.ElasticClient.TermVectorsAsync

Delete  Elasticsearch.Net

Elasticsearch.Net.ElasticLowLevelClient.Delete

Elasticsearch.Net.ElasticLowLevelClient.DeleteAsync

Elasticsearch.Net.ElasticLowLevelClient.DeleteByQuery

Elasticsearch.Net.ElasticLowLevelClient.DeleteByQueryAsync

Elasticsearch.Net.ElasticLowLevelClient.Delete

Elasticsearch.Net.ElasticLowLevelClient.DeleteAsync

Elasticsearch.Net.ElasticLowLevelClient.DeleteByQuery

Elasticsearch.Net.ElasticLowLevelClient.DeleteByQueryAsync

Elasticsearch.Net.ElasticLowLevelClient.DeleteByQueryRethrottle

Elasticsearch.Net.ElasticLowLevelClient.DeleteByQueryRethrottleAsync

Elasticsearch.Net.ElasticLowLevelClient.DeleteByQueryUsingType

Elasticsearch.Net.ElasticLowLevelClient.DeleteByQueryUsingTypeAsync

Delete NEST

Nest.ElasticClient.Delete

Nest.ElasticClient.DeleteAsync

Nest.ElasticClient.DeleteByQuery

Nest.ElasticClient.DeleteByQueryAsync

Nest.ElasticClient.Delete

Nest.ElasticClient.DeleteAsync

Nest.ElasticClient.DeleteByQuery

Nest.ElasticClient.DeleteByQueryAsync

Objects

Icon  Description

DotNet Elasticsearch Cluster

DotNet Elasticsearch Index

DotNet Unknown Elasticsearch Index 
Link type Source and destination of link  Methods supported
belongsTo

From DotNet Elasticsearch Index object to DotNet Elasticsearch Cluster object

-
useLink Between the caller .NET Class / Method objects and DotNet Elasticsearch Index objects

Bulk

BulkAsync

DefaultIndex

 useInsertLink Between the caller .NET Class / Method objects and DotNet Elasticsearch Index objects

Index

IndexAsync

IndexDocument

IndexDocumentAsync

Create

CreateAsync

CreateUsingType

CreateUsingTypeAsync

IndexUsingType

IndexUsingTypeAsync

IndexDocument

Map

MapAsync

IndexDocumentAsync

 useDeleteLink Between the caller .NET Class / Method objects and DotNet Elasticsearch Index objects

Delete

DeleteAsync

DeleteByQuery

DeleteByQueryAsync

DeleteByQueryRethrottle

DeleteByQueryRethrottleAsync

DeleteByQueryUsingType

DeleteByQueryUsingTypeAsync

useSelectLink

Between the caller .NET Class / Method objects and DotNet Elasticsearch Index objects

Search

SearchAsync

DocumentExists

DocumentExistsAsync

Explain

ExplainAsync

Get

GetAsync

Count

CountAsync

CountUsingType

CountUsingTypeAsync

DocumentExists

DocumentExistsAsync

Explain

ExplainAsync

Get

GetAsync

IndexExists

IndexExistsAsync

MultiGet

MultiGetAsync

MultiGetUsingType

MultiGetUsingTypeAsync

MultiTermVectors

MultiTermVectorsAsync

MultiTermVectorsUsingType

MultiTermVectorsUsingTypeAsync

Search

SearchAsync

SearchMvt

SearchMvtAsync

Source

SourceAsync

SourceExists

SourceExistsAsync

SourceUsingType

SourceUsingTypeAsync

TermVectors

TermVectorsAsync

TermVectorsUsingType

TermVectorsUsingTypeAsync

useUpdateLink Between the caller .NET Class / Method objects and DotNet Elasticsearch Index objects

Update

UpdateAsync

UpdateByQuery

UpdateByQueryAsync

UpdateByQueryRethrottle

UpdateByQueryRethrottleAsync

What results can you expect?

Some example scenarios are shown below:

Cluster Creation and Default Index(Elasticsearch.Net and NEST)

class HighLevel
{
        public void UsingConnectionPool()
        {            var uris = new[]
                 {
                    new Uri("http://localhost:9200"),
                    new Uri("http://localhost:9201"), 
                   new Uri("http://localhost:9202"), 
                 };
                var connectionPool = new SniffingConnectionPool(uris);
                var settings = new ConnectionSettings(connectionPool)
                        .DefaultIndex("people");
                var client = new ElasticClient(settings);
        }
}

Cluster Creation From Configuration File

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <section name="resizer" type="ImageResizer.ResizerSection,ImageResizer" requirePermission="false" />
    <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
    <section name="rockConfig" type="Rock.Configuration.RockConfig, Rock" />
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <appSettings>
    <add key="baseUrl" value="http://127.0.0.1:9200" />
    <add key="AllowDuplicateGroupMembers" value="false" />
    <add key="EnableRedisCacheCluster" value="False" />
    <add key="RedisPassword" value="" />
    <add key="RedisEndpointList" value="" />
    <add key="RedisDatabaseNumber" value="0" />
    <add key="CacheManagerEnableStatistics" value="False" />
  </appSettings>

  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Http" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Net.Http.Formatting" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.IdentityModel.Tokens" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-5.2.1.0" newVersion="5.2.1.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.Owin.Security" publicKeyToken="31bf3856ad364e35" culture="neutral" />
          <bindingRedirect oldVersion="0.0.0.0-4.0.0.0" newVersion="4.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.IdentityModel.Protocol.Extensions" publicKeyToken="31bf3856ad364e35" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-1.0.40306.1554" newVersion="1.0.40306.1554" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="Microsoft.AspNetCore.DataProtection.Abstractions" publicKeyToken="adb9793829ddae60" culture="neutral" />
        <bindingRedirect oldVersion="0.0.0.0-2.0.0.0" newVersion="2.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler extension=".cs" language="c#;cs;csharp" warningLevel="4" compilerOptions="/langversion:7.3 /nowarn:1659;1699;1701" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=3.6.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35">
        <providerOption name="UseAspNetSettings" value="false" />
      </compiler>
    </compilers>
  </system.codedom>
</configuration>

Insert Operation(Elasticsearch.Net and NEST)

IndexDocument

public void Indexing()
{
            var person = new Person
            {
                Id = 1,
                FirstName = "Martijn",
                LastName = "Laarman"
            };
            var ndexResponse = client.IndexDocument(person); //<1>
}

IndexDocumentAsync

public async Task IndexingAsync()
{            var person = new Person
            {
                Id = 2,
                FirstName = "Jack",
                LastName = "Mas" 
           };
           var asyncIndexResponse = await client.IndexDocumentAsync(person); 
}

Update Operation(Elasticsearch.Net and NEST)

public static bool updateDocument(string searchID, string first_name, string last_name)
{
        bool status;
             //Update by Partial Document
               var response = client.Update<DocumentAttributes, UpdateDocumentAttributes>(searchID, d => d
                .Index(index)
                .Doc(new UpdateDocumentAttributes
                {
                    FirstName = first_name,
                    LastName = last_name
                 }));            
}

Select Operation(Elasticsearch.Net and NEST)

public void SearchingOnDefaultIndex()        
{
    var searchResponse = client.Search<Person>(s => s
                .From(0)
                .Size(10)
                .Query(q => q
                     .Match(m => m
                        .Field(f => f.FirstName)
                        .Query("Martijn")
                     )
                )
            );
            var people = searchResponse.Documents;        
}

Delete Operation(Elasticsearch.Net and NEST)

public static bool deleteDocument(string index, string searchID)        
{
        bool status;
             var response = client.Delete<DocumentAttributes>(searchID, d => d
                 .Index(index));
        if (response.IsValid)
        {
                 status = true;
             }
           else
           {
                    status = false;
               }
            return status;
}   

Bulk Operations(Elasticsearch.Net and NEST)

public void BulkOperations()        
{
            var people = new object[]
            {
                new { index = new { _index = "people", _type = "person", _id = "1"  }},
                new { FirstName = "Martijn", LastName = "Laarman" },
                new { index = new { _index = "people", _type = "person", _id = "2"  }},
                new { FirstName = "Greg", LastName = "Marzouka" },
                new { index = new { _index = "people", _type = "person", _id = "3"  }},
                new { FirstName = "Russ", LastName = "Cam" },
             };
            var ndexResponse = lowlevelClient.Bulk<StringResponse>(PostData.MultiJson(people));
            string responseStream = ndexResponse.Body;
}

Bulk Operations Using Fluent DSL

public void BulkOperationsUsingFluentDSL ()
{
            var result = client.Bulk(b => b
            .Index<Person>(i => i
                .Document(new Person {Id = 2})
             )   
             .Create<Person>(c => c
                .Document(new Person { Id = 3 })
            )
            .Delete<Person>(d => d
                .Document(new Person { Id = 4 })
            ));
}

Known Limitations

  • If index names are not resolved, the links are created between methods and default or unknown index objects