From 087fddd0b31a664ea39510e8bf61860fe4d11388 Mon Sep 17 00:00:00 2001 From: Finn Carroll Date: Thu, 5 Sep 2024 20:20:53 -0700 Subject: [PATCH] SearchHit id nullable Signed-off-by: Finn Carroll --- .../main/java/org/opensearch/search/SearchHit.java | 12 ++++++++++-- .../transport/protobuf/SearchHitProtobuf.java | 2 ++ server/src/main/proto/serde/SearchHitsProto.proto | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/server/src/main/java/org/opensearch/search/SearchHit.java b/server/src/main/java/org/opensearch/search/SearchHit.java index 2f6cd2643c4b1..01141bb6096a6 100644 --- a/server/src/main/java/org/opensearch/search/SearchHit.java +++ b/server/src/main/java/org/opensearch/search/SearchHit.java @@ -178,11 +178,14 @@ public void fromProtobufStream(StreamInput in) throws IOException { private SearchHitsTransportProto.SearchHitProto toProto() { SearchHitsTransportProto.SearchHitProto.Builder builder = SearchHitsTransportProto.SearchHitProto.newBuilder() .setScore(score) - .setId(id.string()) .setVersion(version) .setSeqNo(seqNo) .setPrimaryTerm(primaryTerm); + if (id != null) { + builder.setId(id.string()); + } + if (nestedIdentity != null) { builder.setNestedIdentity(nestedIdentityToProto(nestedIdentity)); } @@ -224,10 +227,15 @@ private void fromProto(SearchHitsTransportProto.SearchHitProto proto) { seqNo = proto.getSeqNo(); version = proto.getVersion(); primaryTerm = proto.getPrimaryTerm(); - id = new Text(proto.getId()); sortValues = searchSortValuesFromProto(proto.getSortValues()); matchedQueries = proto.getMatchedQueriesMap(); + if (proto.hasId()) { + id = new Text(proto.getId()); + } else { + id = null; + } + if (proto.hasNestedIdentity()) { nestedIdentity = nestedIdentityFromProto(proto.getNestedIdentity()); } else { diff --git a/server/src/main/java/org/opensearch/transport/protobuf/SearchHitProtobuf.java b/server/src/main/java/org/opensearch/transport/protobuf/SearchHitProtobuf.java index cb0c7a23c2c6f..77cdbbc004667 100644 --- a/server/src/main/java/org/opensearch/transport/protobuf/SearchHitProtobuf.java +++ b/server/src/main/java/org/opensearch/transport/protobuf/SearchHitProtobuf.java @@ -73,6 +73,8 @@ public SearchHitProto toProto() { .setSeqNo(seqNo) .setPrimaryTerm(primaryTerm); + + if (nestedIdentity != null) { builder.setNestedIdentity(nestedIdentityToProto(nestedIdentity)); } diff --git a/server/src/main/proto/serde/SearchHitsProto.proto b/server/src/main/proto/serde/SearchHitsProto.proto index 92fdef26732b1..2d8ec55407629 100644 --- a/server/src/main/proto/serde/SearchHitsProto.proto +++ b/server/src/main/proto/serde/SearchHitsProto.proto @@ -49,7 +49,7 @@ Map innerHits */ message SearchHitProto { float score = 1; - string id = 2; + optional string id = 2; int64 version = 3; int64 seq_no = 4; int64 primary_term = 5;