In this project, We will show the usage of ElasticsearchRepository and ElasticsearchTemplates. This project uses Spring-data-elasticsearch and that is compatible with ElasticSearch 2.4.4 only. Don't use ElasticSearch 5.x and above with spring-data-elasticsearch as it is not updated yet with latest version. If you want to use latest ElasticSearch 5.x then you need to directly use Spring with Transport or node client apis. See dependencies details on this link - https://github.com/spring-projects/spring-data-elasticsearch/wiki/Spring-Data-Elasticsearch---Spring-Boot---version-matrix
git clone https://github.com/RajeshBhojwani/spring-boot-elasticsearch.git
mvn clean install
java -jar target\elasticsearch-0.0.1-SNAPSHOT.jar
UserController has api using ElasticsearchTemplate UserRepositoryController has api using ElasticsearchRepository
- POST call for creating new User- http://localhost:8102/new
{
"name": "Sumit",
"userSettings": {
"gender" : "male",
"occupation" : "CA",
"hobby" : "chess"
}
}
-
GET call for Retrieve all Users http://localhost:8102/all
-
Add User setting entry by name http://localhost:8102/settings/Deepika/hobby/poetry
For other apis, check code.
- POST call for creating new User- http://localhost:8102/repo/new
{
"name": "Deepika",
"userSettings": {
"gender" : "Female",
"occupation" : "Software Engineer",
"hobby" : "racing"
}
}
-
GET call for Retrieve all Users - http://localhost:8102/repo/all
-
Add User settings entry by for a userId - http://localhost:8102/repo/settings/AWdeQyaoTJbZRlQtLZfL/hobby/chess
For other apis, check code.
For detail explanation of this project check this blog - https://www.rajeshbhojwani.co.in/2018/12/overview-elasticsearch-real-time.html