Skip to content

sin-to-jin/spring-boot-elasticsearch

Repository files navigation

spring-boot-elasticsearch

CircleCI codebeat badge Official HP MIT License

To support elasticsearch v5.5.1 with spring-boot v2.0.0.M3 and Kibana v5.5.1, Fluentd v2.3.

  • Java v1.8
  • Gradle v4.0.1
  • Spring Boot v2.0.0.M3
  • Tomcat v8
  • Elasticsearch v5.5.1
  • Kibana v5.5.1
  • Fluentd v2.3
  • Spock(Groovy v2.4.12) v1.1

How to Use

only Mac OS

Install Java

brew cask install java

Install Elasticsearch

brew install elasticsearch
elasticsearch -V
elasticsearch # Start Elasticsearch.

Install Kibana

brew install kibana
kibana -V
kibana # Start Kibana.

Install this project

git clone [email protected]:ogasawaraShinnosuke/spring-boot-elasticsearch.git
cd spring-boot-elasticsearch
./gradlew clean
./gradlew build
./gradlew bootRun

Test

./gradlew test

# Coverage Report
./gradlew jacocoTestReport
open build/jacocoHtml/index.html (Optional)

Install Fluentd

wget http://packages.treasuredata.com.s3.amazonaws.com/2/macosx/td-agent-2.3.0-0.dmg # Execute this dmg-file. 
sudo /opt/td-agent/embedded/bin/fluent-gem install fluent-plugin-elasticsearch # Install gem for Fluentd.
sudo launchctl unload /Library/LaunchDaemons/td-agent.plist # Invalidate settings.
sudo launchctl load /Library/LaunchDaemons/td-agent.plist # Activate settings.

Request examples

Check kibana

  • Access to http://localhost:5601

Insert data

curl -XPOST http://localhost:8080/crypto-currencies -d '{"name":"bitcoin","marketCapitalization":46219389522.4,"keywords": ["bitcoin","BTC"]}'
curl -XPOST http://localhost:8080/crypto-currencies -d '{"name":"Ethereum","marketCapitalization":31278008829.5,"keywords": ["Ethereum","ETH"]}'
curl -XPOST http://localhost:8080/crypto-currencies -d '{"name":"Ripple","marketCapitalization":12034938611.6,"keywords":["Ripple","XRP"]}'

Check this data

curl http://localhost:9200/crypto-currencies/_search\?pretty

Operation data

# want to find list
curl -XGET http://localhost:8080/crypto-currencies

# want to find query (include `i` for name parameter)
curl -XGET http://localhost:8080/crypto-currencies?name=*i*

# want to find docID (`AVzJU4hHoL2ZelEv7YH5` is uniq docID)
curl -XGET http://localhost:8080/crypto-currencies/AVzJU4hHoL2ZelEv7YH5

# want to delete docID (`AVzJU4hHoL2ZelEv7YH5` is uniq docID)
curl -XDELETE http://localhost:8080/crypto-currencies/AVzJU4hHoL2ZelEv7YH5

Search by numerical value, List and BetWeen are not implemented yet

Summary Matrix System

  • Fluentd is to build Tomcat's unified logging layer with Elasticsearch, Kibana.
tomcat - fluentd
  |         |
 elasticsearch
      |
    kibana
Server Port Built In Homebrew dmg Version
Tomcat 8080 ✔️ v2.0.0.M3
Fluentd 8888,24230 ✔️ v2.3
Elasticsearch 9200,9300 ✔️ ✔️ v5.4.2
Kibana 5601 ✔️ v5.4.2

It's also possible to use Logstash and Beats.