Demo project showing how to add elasticsearch to a legacy application.
Switch branches/tags
Clone or download
dadoonet Update dependencies (Spring Boot, MySQL, common-lang, dozer)
* Update to Spring Boot 2.1.1
* Update to MySQL 8.0.13
* Update to commons-lang3 3.8.1
* Update to dozer-core 6.4.1
* Remove explicit dependency of javassist
Latest commit 222fcda Dec 7, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src/main Update dependencies (Spring Boot, MySQL, common-lang, dozer) Dec 7, 2018
.env
.gitignore Add .gitignore and update README May 5, 2014
README.markdown Migration to Spring Boot Sep 19, 2018
docker-compose.yml Update to Elasticsearch 6.3.0 Jun 14, 2018
pom.xml Update dependencies (Spring Boot, MySQL, common-lang, dozer) Dec 7, 2018

README.markdown

Add Search to Legacy Application

Introduction

This is a demo project to show how to add elasticsearch to a legacy SQL project.

In this branch, you will find the current legacy version of the project.

Installation

You need to have:

  • Maven
  • JDK8 or higher
  • Postgresql or MySQL 5.7+ up and running

Modify src/main/resources/application.yml file to reflect your own database settings:

# Database connection settings - postgresql
spring.datasource.url: jdbc:postgresql://localhost:5432/dpilato
spring.datasource.username: dpilato
spring.datasource.password:

or

# Database connection settings - MySQL
spring.datasource.url: jdbc:mysql://localhost:3306/person?serverTimezone=UTC&useSSL=false
spring.datasource.username: root
spring.datasource.password:

If you did not create your database yet, just run:

# Postgresql
createdb person
# MySQL
mysqladmin -uroot create person

Build the application:

mvn clean install

Then run it with:

java -jar target/legacy-search-2.0-SNAPSHOT.jar

Or directly run from Maven:

mvn clean spring-boot:run

Note that while developing, you would probably prefer running LegacySearchApp#main() from your IDE to get hot reload of the application.

Play!

Some CRUD operations

# Create one person
curl -XPUT http://127.0.0.1:8080/api/1/person/1 -H "Content-Type: application/json" -d '{"name":"David Pilato"}'

# Read that person
curl http://127.0.0.1:8080/api/1/person/1

# Update full document
curl -XPUT http://127.0.0.1:8080/api/1/person/1 -H "Content-Type: application/json" -d '{"name":"David Pilato", "children":3}'

# Check
curl http://127.0.0.1:8080/api/1/person/1

# Delete
curl -XDELETE http://127.0.0.1:8080/api/1/person/1

# Check (you should get a 404 error)
curl http://127.0.0.1:8080/api/1/person/1

Database Initialisation

# Initialize the database with 1 000 (default) or 10 000 persons
curl http://127.0.0.1:8080/api/1/person/_init
curl http://127.0.0.1:8080/api/1/person/_init?size=10000

Search

# Search for something (`a la google`)
curl "http://127.0.0.1:8080/api/1/person/_search?q=Joe"

You can then access the application using your browser: http://127.0.0.1:8080/. You can also look at advanced search.

Next step

Look at branch 01-direct