Skip to content

Commit

Permalink
SearchHit id nullable
Browse files Browse the repository at this point in the history
Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Sep 6, 2024
1 parent 912ec45 commit 087fddd
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
12 changes: 10 additions & 2 deletions server/src/main/java/org/opensearch/search/SearchHit.java
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public SearchHitProto toProto() {
.setSeqNo(seqNo)
.setPrimaryTerm(primaryTerm);



if (nestedIdentity != null) {
builder.setNestedIdentity(nestedIdentityToProto(nestedIdentity));
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/main/proto/serde/SearchHitsProto.proto
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Map<String, SearchHits> innerHits
*/
message SearchHitProto {
float score = 1;
string id = 2;
optional string id = 2;
int64 version = 3;
int64 seq_no = 4;
int64 primary_term = 5;
Expand Down

0 comments on commit 087fddd

Please sign in to comment.