Is there a .NET client for VSCode?

I am trying to create a file to write ElasticSearch queries from C#. I have seen that there is are 2 official ElasticSearch clients for .NET (Introduction | Elasticsearch.Net and NEST: the .NET clients [7.x] | Elastic) however these are made for Visual Studio. Is there a way to use these packages in VSCode? Or does there exist a similar package? Or are there any alternative ways to use ES API in C#?

These are NuGet packages, you can install them using one of the methods available for installing nuget packages.

You can also look for a VS Code Plugin to help you manage NuGet Packages.

You can use the NuGet packages in VS code as @leandrojmp mentions. NuGet packages can be used anywhere that supports the NuGet package manager API.

To get started in VS Code, assuming you have

  1. a .NET SDK installed
  2. the C# for Visual Studio Code extension

from the Terminal in VS Code

dotnet new console --name DotnetClientExample
cd DotnetClientExample

to create a new console application named DotnetClientExample and go to the project directory.

Then

dotnet add package Nest

to add the latest version of the Nest NuGet package to the project.

Then to use it, as an example, replace contents of Program.cs with

using System;
using Nest;

namespace DotnetClientExample
{
    class Program
    {
        static void Main(string[] args)
        {
            var client = new ElasticClient();
            var infoResponse = client.RootNodeInfo();
            Console.WriteLine($"cluster name is {infoResponse.ClusterName}");
        }
    }
}

which will print the name of the cluster at http://localhost:9200

2 Likes

Thank you very much