Dogukan Sonmez

Currently in Munich, Germany

Java Groovy Python

No-Sql TDD Scrum

Django Shell Cloud

Sept 24 2012

JEST - Java HTTP Rest client for ElasticSearch

In this post you will find information about ElasticSearch, and Jest.

I am not going to rewrite existing information; instead I will link some resources to deep in for each topic.


It is an open source search server developed by Shay Banon author of Compass.

It has really cool features and very easy to start and develop. Check out following links for more information.

Like its name it is a search box for your application. It is fastest way to search your documents. Visit following page to get more information.


It is a Java based REST API to communicate ElasticSearch server via HTTP.

It is an open source project hosted on Sonatype

As previous coolest tools it is also very easy to use.

Let’s assume you have a java based project and you want to use ElasticSearch because you want to index your data and you want to make it simple and easy.

To start add following dependency to your pom.xml


Add Sonatype repository definition to your root pom.xml

   <name>Sonatype Groups</name>

To start get an instance of Jest.

JestClient client = new JestClientFactory().getObject();

Then let’s create an index (it is like a ‘database’ in a relational database.)

There is couple of ways to create index via Jest. Let’s assume you want to create index from configuration file

configuration file:

{"settings" : {
        "number_of_shards" : 1
"mappings" : {
        "type1" : {
            "_source" : { "enabled" : false },
            "properties" : {
                "field1" : { "type" : "string", "index" : "not_analyzed" }

client.execute(new CreateIndex("indexName", "/config/elasticsearch-simple.json"));

After that it’s up to your needs.

If you want to add document to your index Then

Index index = new Index.Builder(source).index("indexName ").type("typeName").build();


type is a like table in relational database

check out elasticsearch glassory

source might be your domain object , a map, or a json string

search your data

JestResult result = client.execute(new Search(query))

List list = result.getSourceAsObjectList(DomainObject.class);

Get a document

Get get = new Get.Builder("1").index("indexName").type("typeName").build();

JestResult result = client.execute(get);

DomainObject myObject = result.getSourceAsObject(DomainObject.class);

Delete a document

client.execute(new Delete.Builder("1").index("indexName ").type("typeName ").build());

For more information about Jest visit

Furthermore check out following example projects.