fix: support all sortable columns and use camelCase for OpenSearch
Add executionId and applicationName to allowed sort fields. Fix sort column mapping to use camelCase field names matching the OpenSearch ExecutionDocument fields instead of snake_case DB column names. This was causing sorts on most columns to either silently fall back to startTime or return empty results from OpenSearch. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -55,16 +55,8 @@ public record SearchRequest(
|
||||
private static final int MAX_LIMIT = 500;
|
||||
|
||||
private static final java.util.Set<String> ALLOWED_SORT_FIELDS = java.util.Set.of(
|
||||
"startTime", "status", "agentId", "routeId", "correlationId", "durationMs"
|
||||
);
|
||||
|
||||
private static final java.util.Map<String, String> SORT_FIELD_TO_COLUMN = java.util.Map.of(
|
||||
"startTime", "start_time",
|
||||
"status", "status",
|
||||
"agentId", "agent_id",
|
||||
"routeId", "route_id",
|
||||
"correlationId", "correlation_id",
|
||||
"durationMs", "duration_ms"
|
||||
"startTime", "status", "agentId", "routeId", "correlationId",
|
||||
"durationMs", "executionId", "applicationName"
|
||||
);
|
||||
|
||||
public SearchRequest {
|
||||
@@ -75,9 +67,12 @@ public record SearchRequest(
|
||||
if (!"asc".equalsIgnoreCase(sortDir)) sortDir = "desc";
|
||||
}
|
||||
|
||||
/** Returns the validated database column name for ORDER BY. */
|
||||
/**
|
||||
* Returns the validated sort field name for OpenSearch ORDER BY.
|
||||
* Field names match the ExecutionDocument record fields (camelCase).
|
||||
*/
|
||||
public String sortColumn() {
|
||||
return SORT_FIELD_TO_COLUMN.getOrDefault(sortField, "start_time");
|
||||
return sortField;
|
||||
}
|
||||
|
||||
/** Create a copy with resolved agentIds (from application name lookup). */
|
||||
|
||||
Reference in New Issue
Block a user