CAST supports Elasticsearch via its NoSQL for .NET extension. Details about how this support is provided for .NET source code is discussed below.

Supported Client Libraries

Elasticsearch.NET

NEST

Supported Operations

OperationMethods Supported
Insert


  • Elasticsearch.Net.ElasticLowLevelClient.Index
  • Elasticsearch.Net.ElasticLowLevelClient.IndexAsync
  • IndexDocument
  • IndexDocumentAsync


Update


  • Elasticsearch.Net.ElasticLowLevelClient.Update
  • Elasticsearch.Net.ElasticLowLevelClient.UpdateAsync
  • Elasticsearch.Net.ElasticLowLevelClient.UpdateByQuery
  • Elasticsearch.Net.ElasticLowLevelClient.UpdateByQueryAsync


Select


  • Elasticsearch.Net.ElasticLowLevelClient.Search
  • Elasticsearch.Net.ElasticLowLevelClient.SearchAsync
  • Elasticsearch.Net.ElasticLowLevelClient.DocumentExists
  • Elasticsearch.Net.ElasticLowLevelClient.DocumentExistsAsync
  • Elasticsearch.Net.ElasticLowLevelClient.Explain
  • Elasticsearch.Net.ElasticLowLevelClient.ExplainAsync
  • Get
  • GetAsync


Delete 


  • Elasticsearch.Net.ElasticLowLevelClient.Delete
  • Elasticsearch.Net.ElasticLowLevelClient.DeleteAsync
  • Elasticsearch.Net.ElasticLowLevelClient.DeleteByQuery
  • Elasticsearch.Net.ElasticLowLevelClient.DeleteByQueryAsync


Objects

Icon Description

DotNet Elasticsearch Cluster

DotNet Elasticsearch Index

DotNet Unknown Elasticsearch Index 

Links

Links are created for transaction and function point needs:

Link typeSource and destination of link Methods supported
parentLink

Between Elasticsearch Cluster object and Elasticsearch Index object


useLinkBetween the caller .NET Class / Method objects and Elasticsearch Index objects


  • Bulk
  • BulkAsync
  • .DefaultIndex
 useInsertLink
  • Index
  • IndexAsync
  • IndexDocument
  • IndexDocumentAsync
 useDeleteLink
  • Delete
  • DeleteAsync
  • DeleteByQuery
  • DeleteByQueryAsync

useSelectLink

  • Search
  • SearchAsync
  • DocumentExists
  • DocumentExistsAsync
  • Explain
  • ExplainAsync
  • Get
  • GetAsync
useUpdateLink
  • Update
  • UpdateAsync
  • UpdateByQuery
  • UpdateByQueryAsync


What results can you expect?

Once the analysis/snapshot generation has completed, you can view the results in the normal manner (for example via CAST Enlighten). Some examples are shown below.

Cluster Creation and Default Index

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);
        }
}



Insert Operation

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


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

Update Operation

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 

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

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

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;
}


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 })
            ));
}

Evolution

Limitations

Future Development