elasticsearchHow can I use Elasticsearch with C#?
Elasticsearch can be used with C# via the official low-level client library NEST.
NEST provides a strongly-typed query DSL that maps 1:1 with the Elasticsearch query DSL, and takes advantage of specific C# features such as covariant results and auto mapping of POCO types.
Example code to connect to an Elasticsearch cluster, index a document, and search for it:
var defaultIndex = "my-index";
var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
    .DefaultIndex(defaultIndex);
var client = new ElasticClient(settings);
// Index a document
var person = new Person { Id = 1, Name = "Martijn Laarman" };
var indexResponse = client.IndexDocument(person);
// Search for the document
var searchResponse = client.Search<Person>(s => s
    .Query(q => q
        .Term(f => f.Name, person.Name)
    )
);
// Output the total number of documents found
Console.WriteLine($"{searchResponse.Total} documents found");
Output example
1 documents found
The code above does the following:
- Creates a 
ConnectionSettingsobject, which specifies the connection parameters to the Elasticsearch cluster. - Creates an 
ElasticClientobject, using theConnectionSettings. - Indexes a 
Personobject, which is a custom POCO type. - Searches for the document using a 
Termquery on theNamefield. - Outputs the total number of documents found.
 
Helpful links
More of Elasticsearch
- How can I use elasticsearch zone awareness to improve my software development?
 - How can I use Elasticsearch and ZFS together?
 - How can I use Elasticsearch and Zabbix together for software development?
 - How can I use Yandex Mirror to access Elasticsearch data?
 - How can I perform a case-insensitive wildcard search using Elasticsearch?
 - How can I use Elasticsearch to diagnose "yellow" issues?
 - How do I set up an Elasticsearch Yum repository?
 - How can I use YouTube to learn about Elasticsearch?
 - How can I check the status of a yellow index in Elasticsearch?
 - How can I set up and use Elasticsearch on the Yandex Cloud platform?
 
See more codes...