Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork15
The goal of this project is to implement an application called product-app. It consists of two Spring Boot services: product-api (backend) and product-ui (frontend). Data will be stored in Elasticsearch
ivangfr/springboot-elasticsearch-thymeleaf
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
The goal of this project is to implement an application calledproduct-app. It consists of twoSpring Boot services:product-api (backend) andproduct-ui (frontend). The data will be stored inElasticsearch.
Onivangfr.github.io, I have compiled my Proof-of-Concepts (PoCs) and articles. You can easily search for the technology you are interested in by using the filter. Who knows, perhaps I have already implemented a PoC or written an article about what you are looking for.
product-api
Spring BootWeb Java application that exposes a REST API to manage products. Product information is stored inElasticsearch.product-apiusesSpring Data Elasticsearchto persist/query/delete data inElasticsearch.product-ui
Spring BootWeb application that was implemented usingThymeleafas HTML template. Also, it usesHttp Interfacesto simplify HTTP remote access toproduct-api.
Open a terminal and navigate to the
springboot-elasticsearch-thymeleafroot folder run:docker compose up -d
Wait for
ElasticsearchDocker container to be up and running. To verify it, run:docker ps -a
Note | In the following steps, we will create an index, an alias and do a reindex using pre-defined scripts. In case you prefer to do it step-by-step callingElasticsearch API, refer toCreating indexes, alias and reindexing using Elasticsearch API. |
In a terminal, make sure you are in the
springboot-elasticsearch-thymeleafroot folder;Run the following script to create the index
ecommerce.products.v1with the aliasecommerce.products(you can use the default values by just pressingEnteron every user input):./create-index.sh
If you want to insert some products, run:
./insert-products.sh
If you want to fix the
referenceproperty mapping error (explained below), run:./reindex.sh
The script
./reindex.shis used to reindex one index to another. The default will reindex fromecommerce.products.v1toecommerce.products.v2. The only difference betweenelasticsearch/mapping-v1.json(used byecommerce.products.v1) andelasticsearch/mapping-v2.json(used byecommerce.products.v2) is thetypeof thereferenceproperty. In the former, it is set the typetextand, in the latter, the typekeyword.It’s interesting because the
referenceproperty has some special characters. An example ofreferencecode isSBES@DDR4-10000. As it has the typetext,Elasticsearch(using thestandardanalyzer) splits the content in tokens ['SBES', 'DDR4', 10000]. So, for example, if you are looking for a product withDDR4RAM and, for some reason, the stringDDR4is present in the reference code of some product X, the product X will be selected, even if it doesn’t haveDDR4in its description.So, the script
./reindex.shaims to fix it, setting the typekeywordto thereferenceproperty. TheDDR4search issue won’t happen again because, from now on,Elasticsearchwon’t tokenize the content present in thereferenceproperty.
Below are the steps to start and run the applications usingMaven. We will need to open a terminal for each one. Make sure you are in thespringboot-elasticsearch-thymeleaf root folder while running the commands.
product-api
./mvnw clean spring-boot:run --projects product-api
product-ui
./mvnw clean spring-boot:run --projects product-ui -Dspring-boot.run.jvmArguments="-Dserver.port=9080"
Build Docker Images
In a terminal, make sure you are in the
springboot-elasticsearch-thymeleafroot folder;Run the following script:
./build-docker-images.sh
Environment Variables
product-api
Environment Variable Description ELASTICSEARCH_URISSpecify uris of the
Elasticsearchsearch engine to use (defaultlocalhost:9200)product-ui
Environment Variable Description PRODUCT_API_URLSpecify url of the
product-apiservice to use (defaulthttp://localhost:8080)
Run Docker containers
In a terminal, make sure you are in the
springboot-elasticsearch-thymeleafroot folder;Run the following script:
./start-apps.sh
| Application | URL |
|---|---|
product-api | |
product-ui |
To stop applications:
If they were started with
Maven, go toproduct-apiandproduct-uiterminals and pressCtrl+C;If they were started as Docker containers, go to a terminal and, inside the
springboot-elasticsearch-thymeleafroot folder, run the script below:./stop-apps.sh
To stop and remove docker compose containers, network and volumes, go to a terminal and, inside the
springboot-elasticsearch-thymeleafroot folder, run the following command:docker compose down -v
About
The goal of this project is to implement an application called product-app. It consists of two Spring Boot services: product-api (backend) and product-ui (frontend). Data will be stored in Elasticsearch
Topics
Resources
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.
Packages0
Uh oh!
There was an error while loading.Please reload this page.

