From be1ad009ee1611d820872ce3e5633c729e19e6e9 Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Thu, 29 Aug 2024 12:28:01 -0700 Subject: [PATCH] Collapse field to optional Signed-off-by: Finn Carroll --- .../opensearch/transport/protobuf/SearchHitsProtobuf.java | 6 +++++- server/src/main/proto/serde/SearchHitsProto.proto | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/server/src/main/java/org/opensearch/transport/protobuf/SearchHitsProtobuf.java b/server/src/main/java/org/opensearch/transport/protobuf/SearchHitsProtobuf.java index b46181f3e55b4..76518a345a6c7 100644 --- a/server/src/main/java/org/opensearch/transport/protobuf/SearchHitsProtobuf.java +++ b/server/src/main/java/org/opensearch/transport/protobuf/SearchHitsProtobuf.java @@ -55,12 +55,16 @@ public void fromProtobufStream(StreamInput in) throws IOException { } SearchHitsProto toProto() { - SearchHitsProto.Builder builder = SearchHitsProto.newBuilder().setMaxScore(maxScore).setCollapseField(collapseField); + SearchHitsProto.Builder builder = SearchHitsProto.newBuilder().setMaxScore(maxScore); for (SearchHit hit : hits) { builder.addHits(new SearchHitProtobuf(hit).toProto()); } + if (collapseField != null) { + builder.setCollapseField(collapseField); + } + if (totalHits != null) { TotalHitsProto.Builder totHitsBuilder = TotalHitsProto.newBuilder() .setRelation(totalHits.relation.ordinal()) diff --git a/server/src/main/proto/serde/SearchHitsProto.proto b/server/src/main/proto/serde/SearchHitsProto.proto index 9a5055e685c2e..92fdef26732b1 100644 --- a/server/src/main/proto/serde/SearchHitsProto.proto +++ b/server/src/main/proto/serde/SearchHitsProto.proto @@ -23,7 +23,7 @@ Object[] collapseValues */ message SearchHitsProto { float max_score = 1; - string collapse_field = 2; + optional string collapse_field = 2; bytes sort_fields = 3; bytes collapse_values = 4; optional TotalHitsProto total_hits = 5;