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;