C# - ElasticSearch - Basic Search using Nest and ElasticSearch.Net libraries

This is an example using ElasticSearch in C#:

 
ConnectionToES.cs
===========================================================================
 
using Elasticsearch.Net;
using Nest;
using System;
 
namespace DesktopSearchApp
{
    class ConnectionToES
    {
        public static ElasticClient EsClient()
        {
            ConnectionSettings connectionSettings;
            ElasticClient elasticClient;
            StaticConnectionPool connectionPool;
 
            //Connection string for Elasticsearch
            /*connectionSettings = new ConnectionSettings(new Uri("https://localhost Jump :9200/")); //local PC
            elasticClient = new ElasticClient(connectionSettings);*/
 
            //Multiple node for fail over (cluster addresses)
            var nodes = new Uri[]
            {
                new Uri("https://myelasticsearchserver:9200/"),
                //new Uri("Add server 2 address")   //Add cluster addresses here
                //new Uri("Add server 3 address")
            };
 
            connectionPool = new StaticConnectionPool(nodes);
            connectionSettings = new ConnectionSettings(connectionPool);
            elasticClient = new ElasticClient(connectionSettings);
 
            return elasticClient;
        }
 
 
    }
}
 
 
 
formClass.cs
===========================================================================
 
using System;
using System.Windows.Forms;
 
 
 
class ListBoxItem
{
    public string model { get; set; }
    public string id { get; set; }
}
 
namespace DesktopSearchApp
{
    public partial class formClass : Form
    {
        public formClass()
        {
            InitializeComponent();
        }
                
        private void btOK_Click(object sender, EventArgs e)
        {
            var response = new SearchES().SearchData(txtSearch.Text);
 
            lstResult.Items.Clear();
           
 
            foreach (var hit in response.Hits)
            {
                lstResult.ValueMember = "Model";
                lstResult.DisplayMember = "ID";
 
                
                lstResult.Items.Add(new ListBoxItem
                {
                    id = hit.Source.model.ToString(),
                    model = hit.Source.id.ToString()
                });
                
            }
 
            
 
        }
    }
}