Skip to content

Latest commit

 

History

History
 
 

livelessons-data-elasticsearch

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

Lesson 4: Working With Data (Elasticsearch)

Introduction

This example shows how you can connect your microservce to Elasticsearch. In order to run an instance of elasticsearch on docker, you can run the following command:

$ docker run -d --name elasticsearch -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" elasticsearch:6.8.6

Building and running the sample

Use the following commands to build run the application:

$ mvn clean package
$ java -jar target/livelessons-data-elasticsearch-1.0.0-SNAPSHOT.jar

The example uses a local server to store data. If you want to talk to a remote server you can set spring.data.elasticsearch.cluster-name and spring.data.elasticsearch.cluster-nodes properties.

Understanding the code

The familiar Car domain is used again in this example. This time Car is a elasticsearch document (signified with the Spring Data @Document annotation). The same Repository logic is used as before providing a findByMakeIgnoringCase method.

The DataElasticsearchApplication class also shows how you can use the ElasticsearchTemplate to make native elasticsearch queries. In this case we are performing a fuzzy search for manufacturers like ronda.