Saturday, 10 October 2015

IBM Bluemix - Spring Boot Elasticsearch Repositories demo

I decided to take the Elasticsearch repositories as part of the Spring Data project for a test drive. The Spring boot Elasticsearch repositories are described in the link below.

In this example I create a basic Spring Boot application using Elasticsearch, Web, Rest Repositories along with Thymeleaf / Bootstrap as the view pages. The code for this is on GitHub which also provides the "Deploy to Bluemix" button to deploy to your own instance of this application into your own Bluemix accout.

Like all Spring Data Repositories you can create an interface and be given basic CRUD operations to the Elastisearch DOCUMENT as shown below.


import java.util.List;

public interface EmployeeRepository extends ElasticsearchRepository<Employee, String>
    public List<Employee> findByFirstNameContaining(String firstName);


@Document(indexName = "employee", type = "employee", shards = 1, replicas = 0, refreshInterval = "-1")
public class Employee
    private String id;
    private String firstName;
    private String lastName;
    private String job;
    private int deptNo;

    public Employee()


If you don't have a IBM DevOps Jazzhub account the manifest.yml can be used if you clone the project, and compile it using maven with "mvn package". Be sure to alter the application name / host to be a unique name within Bluemix.

 - name: pas-sb-elastic
   memory: 450M
   path: ./target/SpringBootElasticSearch-0.0.1-SNAPSHOT.jar
   instances: 1
   host: pas-sb-elastic
   buildpack: java_buildpack

Example Deployment

pasapicella@pas-macbook-pro:~/ibm/DemoProjects/spring-starter/jazzhub/SpringBootElasticSearch$ cf push
Using manifest file /Users/pasapicella/ibm/DemoProjects/spring-starter/jazzhub/SpringBootElasticSearch/manifest.yml

Creating app pas-sb-elastic in org / space dev as

Using route
Binding to pas-sb-elastic...

Uploading pas-sb-elastic...
Uploading app files from: /Users/pasapicella/ibm/DemoProjects/spring-starter/jazzhub/SpringBootElasticSearch/target/SpringBootElasticSearch-0.0.1-SNAPSHOT.jar
Uploading 1M, 133 files
Done uploading

Starting app pas-sb-elastic in org / space dev as
-----> Downloaded app package (35M)
-----> Java Buildpack Version: v3.0 |
-----> Downloading Open Jdk JRE 1.8.0_60 from (2.7s)
       Expanding Open Jdk JRE to .java-buildpack/open_jdk_jre (1.7s)
-----> Downloading Spring Auto Reconfiguration 1.10.0_RELEASE from (0.9s)

-----> Uploading droplet (79M)

0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
0 of 1 instances running, 1 starting
1 of 1 instances running

App started


App pas-sb-elastic was started using this command `SERVER_PORT=$PORT $PWD/.java-buildpack/open_jdk_jre/bin/java -cp $PWD/.:$PWD/.java-buildpack/spring_auto_reconfiguration/spring_auto_reconfiguration-1.10.0_RELEASE.jar$TMPDIR -XX:OnOutOfMemoryError=$PWD/.java-buildpack/open_jdk_jre/bin/ -Xmx329386K -Xms329386K -XX:MaxMetaspaceSize=64M -XX:MetaspaceSize=64M -Xss975K org.springframework.boot.loader.JarLauncher`

Showing health and status for app pas-sb-elastic in org / space dev as

requested state: started
instances: 1/1
usage: 450M x 1 instances
last uploaded: Sat Oct 10 10:20:52 UTC 2015
stack: cflinuxfs2
buildpack: java_buildpack

     state     since                    cpu    memory           disk           details
#0   running   2015-10-10 09:22:42 PM   0.3%   425.1M of 450M   158.1M of 1G

The application is currently deployed and is accessible at the URL below.

More Information

No comments: