Elastic Search Nest DLL Upgradation

Introduction

In this blog, we are discussing about Nest.dll update in elastic search project. A few days back I have involved in upgrading the Nest.dll from 6.8 to 7.17.1 version and faced some dificulties that I will be discussing on issues.

Step 1 - We need to upgrade the Elastic instance from 6.8 to 7.17.1 in cloud console.

Step 2 - Using visual studio update the Nest verstion from 6.8 to 7.17.1 

Step 3 -  By making the above changes if you run your project you will be getting some complie time issues beacuse of some changes in the new version. Please check the below code snippet to understand the difference.

Code for checking index exist or not in 6.8 version 

if (client.IndexExists(IndexName).Exists)
{
}

After Nest.dll upgrade in 7.17.1 
if (client.Indices.Exists(IndexName).Exists)

Similar to like this we need to fix the other compile time's issue's.

Step 4 - After resolving all the complie time issues there will be chance of getting run time issues while connecting to the elastic instance. I got the "System.Threading.SemaphoreSlim.CheckDispose()" exception, to resolve this issue we need to make some code changes while connecting the elastic node.

In 6.8 Nest.dll

using var pool = new StaticConnectionPool(url);
using var settings = new ConnectionSettings(pool);

After upgrade

var node = new Uri(Url);
var settings = new ConnectionSettings(node);

We need to remove the below line for fixing this issue.

using var pool = new StaticConnectionPool(url);

Step 5 - Once by making all these changes we will be able to make a call to elastic node and we can get the response. Please check the complete code for connecting elastic node.

using System;
using Nest;

namespace NESTLibraryUpgrade
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello NEST Library!");
            var node = new Uri("uri");
            var settings = new ConnectionSettings(node);
            settings.BasicAuthentication("username", "password");
            var elasticClient = new ElasticClient();
            var checkConnection = elasticClient.Ping().IsValid;
             
            // class 
            var tweet = new Tweet
            {
                Id = 1,
                User = "madan",
                PostDate = new DateTime(2009, 11, 15),
                Message = "Trying out NEST, so far so good?"
            };
            // code reference from below link
            //https://github.com/elastic/elasticsearch-net#indexing
             var createResponse = elasticClient.Indices.Create("tweettest", idx => idx.Index("mytweetindex"));
           Console.WriteLine(createResponse.Result);
        }
        public class Tweet
        {
            public int Id { get; set; }
            public string User { get; set; }
            public DateTime PostDate { get; set; }
            public string Message { get; set; }
        }
    }
}

Summary

In this blog, we learned about upgrading Nest library from 6.8 to 7.17.1.

I hope that you find it helpful. Eat->Code->Sleep->Repeat.