Avisi Blog

Elasticsearch flattens the learning curve for search engine technology

Geschreven door Gert-Jan van de Streek | 01 February 2012

While evaluating Lucene and Solr for use in our product I stumbled upon elasticsearch. Elasticsearch, like Solr is based on Lucene. But wow... I am impressed by the work that has been put into elasticsearch. The learning curve for search engine technology is usually quite steep but the quys behind elasticsearch managed to flatten that curve in many ways.

 

 

Elasticsearch promises to be easier and cool, bonsai cool. And it really is. Let me show you code from a unit test from my evaluation:

create a search server:

 

Node server = nodeBuilder().build();
server.start();

Get a client to talk to that server:

 

<code>Client client = server.client();</code>

Put some data in:

 

client.prepareIndex("key_index", "key", id)
.setSource(jsonBuilder()
.startObject()
.field("name", "a name")
.endObject())
.execute()
.actionGet();

query the data:

 

SearchResponse response = client.prepareSearch(INDEX_NAME)
.setQuery(termQuery("name", "title"))
.execute()
.actionGet();

See what I mean? Easy! And cool!

 

The thing that makes elasticsearch so easy to learn is the fluent API. You may like fluent  builders or not, for me it works. It helps explore the multitude of features in the elasticsearch API.

 

(the complete unit test code can be found here or simply cloned from git: git clone git://gist.github.com/1717488.git gist-1717488)