Introduction

I heard of Elasticsearch before but while at NDC-London I saw it put to work and I immediately fell i love with it.

This is how software is supposed to work. Install and let it figure out itself.

Elasticsearch is a distributed restful search and analytics server based on Lucene. So if you feel the need to add fulltext index searching to your application this is the software to go for.

Installation

The one thing Elasticsearch claims is that it is easy to install and get setup in a cluster. Since Linux is cheap and cheerful I decided to download and install Mint 16 as a VM and install ElasticSearch on that. I <3 mint BTW (and now I’m a hipster, right?)

Once you have Mint installed go to the Elasticsearch download page and select the DEB package that will install just fine on Mint.

Once you have done that goto your favorite browser and check if it installed ok by going to http://localhost:9200 which should give you this.

The install also set up the firewall so that port is now also available from your host machine.

Playing

Now that we have set it up and also tried it from our host machine we can start playing around with it. I would recommend reading the blogarticle by Joel Abrahamsson.

I would also recommend using chrome and install the sense extension to get started.

And here are the results of the Belgian jury.

Go read the blog by Joel to get you going.

Here a few of the commands I used.

PUT /plants/plant/1
{
    "name":"Quercus"
}

The above command will create an index if it not yet exists, create the type if it not yet exists and create the entry with an id of 1 and put that object with a name property and a value of Quercus in it.

If you run that command again it will not overwrite the object but create a new version instead.

This being the result.

{

“ok”: true,

“_index”: “plants”,

“_type”: “plant”,

“_id”: “1”,

“_version”: 1

}

PUT /plants/plant/2
{
    "name":"Fagus"
}

The above will just create a second entry with an id of 2 in the same index.

With this as the result.

{

“ok”: true,

“_index”: “plants”,

“_type”: “plant”,

“_id”: “2”,

“_version”: 1

}

GET /plants/plant/1

The above will get you the entry with id 1 from the index plants with a type plant.

With this as the result.

{

“_index”: “plants”,

“_type”: “plant”,

“_id”: “1”,

“_version”: 1,

“exists”: true,

“_source”: {

“name”: “Quercus”

}

}

GET /plants/plant/2

The above will get you the entry with id 2 from the index plants with a type plant.

With this as the result.

{

“_index”: “plants”,

“_type”: “plant”,

“_id”: “2”,

“_version”: 1,

“exists”: true,

“_source”: {

“name”: “Fagus”

}

}

POST /plants/plant/_search { "query": { "query_string": { "query": "*u*" } } } The above will search for any entry with a u in it.

With this as the result.

{

“took”: 9,

“timed_out”: false,

“_shards”: {

“total”: 5,

“successful”: 5,

“failed”: 0

},

“hits”: {

“total”: 2,

“max_score”: 1,

“hits”: [

{

“_index”: “plants”,

“_type”: “plant”,

“_id”: “2”,

“_score”: 1,

“_source”: {

“name”: “Fagus”

}

},

{

“_index”: “plants”,

“_type”: “plant”,

“_id”: “1”,

“_score”: 1,

“_source”: {

“name”: “Quercus”

}

}

]

}

}

Now go and play with it yourself.

Conclusion

ElasticSearch is very easy to set up and get going and very easy to use with it’s RESTFull interface (whatever REST may be). This was just a post to get you interested. But I’m sure I was the last person in this world to get in to this.