C# application connected to ElasticSearch server

Some time ago I mentioned that I will start playing around with ElasticSearch. This is the search engine which is based on Lucene but can be easily distributed to the cloud. There is a server side (git repository) which is responsible for building the indexes and for distributing the requests.

Start the server

This is the simplest step – you need to download source from http://www.elasticsearch.org/ and extract it. Then run bin\elasticsearch.bat and voila! For the first project there is no more interesting things so far (more interesting things will come when the indexes will just be too big to maintain it on one ES server).

Test the connection

The documentation of the ElasticSearch suggest that we should use curl. Of course that is cool if we would like to check whether the connection is established – but more fun we will have when playing with C# code. 🙂

Simple application testing the server

OK, so we have a running server. For todays post the only thing to be done is the test of the connection. ES offers us the RESTful interface which we can easily consume in our application

string uri = "http://localhost:9200/";

var req = System.Net.WebRequest.Create(uri);
System.Net.WebResponse resp = req.GetResponse();
System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());


The result we get is shown on the picture below.


This is the information from the server that it exists and the default response for the server.

As you can see parsing it is not a very beautiful way of connection from the C# application – one need to consume the response (JSON data) and act according to the response. Building the query is also quite tricky.

I have found one of the .NET clients – PlainElastic.Net which seems to be a good choice to go next.

Stay tuned for more ES posts..


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s