Skip to content

Commit

Permalink
implement code review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Dec 5, 2024
1 parent 6337a58 commit b99c322
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -87,7 +89,9 @@ public Mono<ResponseEntity<GenericMessage>> 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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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.
*
Expand Down Expand Up @@ -42,6 +49,10 @@ private void processAggregate(Aggregate aggregate, Map<String, Long> countMap) {
processTermsAggregate(aggregate, countMap);
} else if (aggregate.isDateRange()) {
processDateRangeAggregate(aggregate, countMap);
} else {
log.debug(
"Unsupported aggregation type encountered: {}",
aggregate.getClass().getSimpleName());
}
}

Expand Down

0 comments on commit b99c322

Please sign in to comment.