diff --git a/boot-mongodb-elasticsearch/src/main/java/com/example/mongoes/web/controller/RestaurantController.java b/boot-mongodb-elasticsearch/src/main/java/com/example/mongoes/web/controller/RestaurantController.java index ca3c53192..caede0a4c 100644 --- a/boot-mongodb-elasticsearch/src/main/java/com/example/mongoes/web/controller/RestaurantController.java +++ b/boot-mongodb-elasticsearch/src/main/java/com/example/mongoes/web/controller/RestaurantController.java @@ -9,6 +9,8 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.Size; import java.net.URI; +import java.net.URLEncoder; +import java.nio.charset.StandardCharsets; import org.springframework.data.elasticsearch.core.SearchPage; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.GetMapping; @@ -87,7 +89,9 @@ public Mono> createRestaurant( URI.create( String.format( "/api/restaurant/name/%s", - restaurantRequest.name()))) + URLEncoder.encode( + restaurantRequest.name(), + StandardCharsets.UTF_8)))) .body( new GenericMessage( "restaurant with name %s created" diff --git a/boot-mongodb-elasticsearch/src/main/java/com/example/mongoes/web/service/AggregationProcessor.java b/boot-mongodb-elasticsearch/src/main/java/com/example/mongoes/web/service/AggregationProcessor.java index 685393cb0..9f4c341c1 100644 --- a/boot-mongodb-elasticsearch/src/main/java/com/example/mongoes/web/service/AggregationProcessor.java +++ b/boot-mongodb-elasticsearch/src/main/java/com/example/mongoes/web/service/AggregationProcessor.java @@ -3,16 +3,23 @@ import co.elastic.clients.elasticsearch._types.aggregations.Aggregate; import java.util.HashMap; import java.util.Map; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.data.elasticsearch.client.elc.ElasticsearchAggregation; import org.springframework.stereotype.Service; /** * Processes Elasticsearch aggregations and transforms them into a structured map format. Supports * 'terms' and 'dateRange' aggregation types. + * + *

Example output format: { "termAggregation": {"term1": 10, "term2": 20}, + * "dateRangeAggregation": {"2023-01-01 - 2023-12-31": 100} } */ @Service class AggregationProcessor { + private static final Logger log = LoggerFactory.getLogger(AggregationProcessor.class); + /** * Processes Elasticsearch aggregations and returns a structured map of results. * @@ -42,6 +49,10 @@ private void processAggregate(Aggregate aggregate, Map countMap) { processTermsAggregate(aggregate, countMap); } else if (aggregate.isDateRange()) { processDateRangeAggregate(aggregate, countMap); + } else { + log.debug( + "Unsupported aggregation type encountered: {}", + aggregate.getClass().getSimpleName()); } }