Une application Spring Boot pour explorer et apprendre Elasticsearch.
- Spring Boot 4.0.6 avec Spring Data Elasticsearch
- Elasticsearch 7.17.16 (via Docker)
- Kibana 7.17.16 (Interface de gestion Elasticsearch - optionnel)
- REST API pour créer, rechercher et supprimer des documents
- Java 17+
- Maven 3.8+
- Docker et Docker Compose
- Port 8080 (Spring Boot), 9200 (Elasticsearch), 5601 (Kibana)
docker-compose up -dCela démarre :
- Elasticsearch sur http://localhost:9200
- Kibana sur http://localhost:5601
Vérifiez que Elasticsearch est opérationnel :
curl http://localhost:9200mvn clean installjava -jar target/testelasticsearch-0.0.1-SNAPSHOT.jarL'application démarre sur http://localhost:8080
curl -X POST http://localhost:8080/api/books \
-H "Content-Type: application/json" \
-d '{
"id":"1",
"title":"Elasticsearch Guide",
"content":"A comprehensive guide to Elasticsearch",
"author":"John Doe"
}'Réponse:
{
"id":"1",
"title":"Elasticsearch Guide",
"content":"A comprehensive guide to Elasticsearch",
"author":"John Doe"
}curl -X GET "http://localhost:8080/api/books/search?query=Elasticsearch"Réponse:
[
{
"id":"1",
"title":"Elasticsearch Guide",
"content":"A comprehensive guide to Elasticsearch",
"author":"John Doe"
}
]curl -X DELETE http://localhost:8080/api/books/1src/main/
├── java/fr/robinjesson/testelasticsearch/
│ ├── TestelasticsearchApplication.java # Point d'entrée
│ ├── api/
│ │ └── BookController.java # REST endpoints
│ ├── model/
│ │ └── Book.java # Entité Elasticsearch
│ ├── repo/
│ │ └── BookRepository.java # Repository Elasticsearch
│ ├── service/
│ │ └── BookService.java # Logique métier
│ └── config/
│ └── ElasticsearchConfig.java # Configuration
└── resources/
├── application.properties # Config Spring
└── elasticsearch/mappings/
└── books.json # Mapping Elasticsearch
Les paramètres Elasticsearch sont configurés dans application.properties :
spring.elasticsearch.uris=http://localhost:9200
spring.elasticsearch.ssl.verification-mode=none# Si lancée au premier plan : Ctrl+C
# Si lancée en background : kill <PID>docker-compose downPour supprimer aussi les données :
docker-compose down -v-
Vérifiez que le conteneur est en cours d'exécution :
docker-compose ps
-
Vérifiez la connexion :
curl http://localhost:9200
-
Consultez les logs :
docker-compose logs elasticsearch
Modifiez les ports dans docker-compose.yml ou application.properties, ou arrêtez les services qui les utilisent.
Assurez-vous que Java 17 ou supérieur est utilisé :
java -version- L'index
booksest créé automatiquement au premier démarrage - Les documents sont stockés en JSON dans Elasticsearch
- Les recherches utilisent l'analyseur "standard" pour la tokenisation
- Le champ
authorest un keyword (pas analysé) - Les champs
titleetcontentsont des text fields (analysés)