This example demonstrates how to use Spring Data Elasticsearch to do simple CRUD operation.
You can find the tutorial about this example at the below link:
https://blog.madadipouya.com/2019/05/01/getting-started-with-spring-data-elasticsearch/
For this example, a Book controller created that allows to do the following operations with Elasticsearch:
- Get list of all books
- Create a book
- Update a book by Id
- Delete a book by Id
- Search for a book by ISBN
- Fuzzy search for books by author and title
The first thing to do is to start Elasticsearch. For that you can use the docker-compose file in this project and run it like this:
$ docker-compose -f docker-compose up -dIt brings Elasticsearch up on a single node cluster with the cluser name elasticsearch.
Then you can run the application like below:
$ ./mvnw spring-boot:runIf your Elasticsearch URI is not localhost and/or the cluster name is different simply override one or both of the following environment variable:
ES_URIES_CLUSTER_NAME
Once everything is up and running open the browser and go to http://localhost:8080. You should see Swagger to interact with.