Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poc search protobuf #393

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Converting SearchHits to a proto message
Signed-off-by: Vacha Shah <vachshah@amazon.com>
VachaShah committed Dec 12, 2023
commit 9ec8a1ae9ea4b996660f071e0cccf4c148ae6149
Original file line number Diff line number Diff line change
@@ -55,7 +55,6 @@
*/
public final class FetchSearchResult extends SearchPhaseResult {

// TODO: Write SearchHits as a proto message
private SearchHits hits;
// client side counter
private transient int counter;
Original file line number Diff line number Diff line change
@@ -234,7 +234,7 @@ private ProtobufShardSearchRequest(

if (scroll != null) {
// TODO: Write Scroll as a proto message
builder.setScroll(ByteString.copyFrom(convertToBytes(scroll)));
builder.setScroll(ShardSearchRequestProto.Scroll.newBuilder().setKeepAlive(scroll.keepAlive().getStringRep()));
}
builder.setNowInMillis(nowInMillis);

@@ -377,13 +377,6 @@ public boolean allowPartialSearchResults() {
}

public Scroll scroll() {
ByteArrayInputStream in = new ByteArrayInputStream(this.shardSearchRequestProto.getScroll().toByteArray());
try (ObjectInputStream is = new ObjectInputStream(in)) {
return (Scroll) is.readObject();
} catch (ClassNotFoundException | IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}

Original file line number Diff line number Diff line change
@@ -138,7 +138,7 @@ public QuerySearchResult(ShardSearchContextId contextId, SearchShardTarget shard
.setIndexName(shardTarget.getShardId().getIndexName())
.setIndexUUID(shardTarget.getShardId().getIndex().getUUID())
.build();
QuerySearchResultProto.QuerySearchResult.SearchShardTarget searchShardTarget = QuerySearchResultProto.QuerySearchResult.SearchShardTarget.newBuilder()
QuerySearchResultProto.SearchShardTarget searchShardTarget = QuerySearchResultProto.SearchShardTarget.newBuilder()
.setNodeId(shardTarget.getNodeId())
.setShardId(shardIdProto)
.setClusterAlias(shardTarget.getClusterAlias())
55 changes: 54 additions & 1 deletion server/src/main/proto/server/FetchSearchResultProto.proto
Original file line number Diff line number Diff line change
@@ -13,10 +13,63 @@ syntax = "proto3";
package org.opensearch.server.proto;

import "server/ShardSearchRequestProto.proto";
import "server/QuerySearchResultProto.proto";

option java_outer_classname = "FetchSearchResultProto";

message FetchSearchResult {
ShardSearchContextId contextId = 1;
optional bytes hits = 2;
optional SearchHits hits = 2;
}

message SearchHits {
TotalHits totalHits = 1;
float maxScore = 2;
int32 size = 3;
repeated SearchHit hits = 4;
/* optional repeated SortField sortFields = 5; */
optional string collapseField = 5;
repeated bytes collapseValues = 6;
}

message SearchHit {
int32 docId = 1;
float score = 2;
string id = 3;
NestedIdentity nestedIdentity = 4;
int64 version = 5;
int64 seqNo = 6;
int64 primaryTerm = 7;
bytes source = 8;
map<string, DocumentField> documentFields = 9;
map<string, DocumentField> metaFields = 10;
map<string, HighlightField> highlightFields = 11;
SearchSortValues sortValues = 12;
repeated string matchedQueries = 13;
/* Explanation explanation = 14;*/
SearchShardTarget shard = 14;
string index = 15;
string clusterAlias = 16;
map<string, bytes> sourceAsMap = 17;

message NestedIdentity {
string field = 1;
int32 offset = 2;
NestedIdentity child = 3;
}

message DocumentField {
string name = 1;
repeated bytes values = 2;
}

message HighlightField {
string name = 1;
repeated string fragments = 2;
}

message SearchSortValues {
repeated bytes formattedSortValues = 1;
repeated bytes rawSortValues = 2;
}
}
29 changes: 15 additions & 14 deletions server/src/main/proto/server/QuerySearchResultProto.proto
Original file line number Diff line number Diff line change
@@ -41,16 +41,6 @@ message QuerySearchResult {
float maxScore = 2;
}

message TotalHits {
int64 value = 1;
Relation relation = 2;

enum Relation {
EQUAL_TO = 0;
GREATER_THAN_OR_EQUAL_TO = 1;
}
}

message TopDocs {
TotalHits totalHits = 1;
repeated ScoreDoc scoreDocs = 2;
@@ -70,9 +60,20 @@ message QuerySearchResult {
}
}

message SearchShardTarget {
string nodeId = 1;
ShardId shardId = 2;
string clusterAlias = 3;
}

message SearchShardTarget {
string nodeId = 1;
ShardId shardId = 2;
string clusterAlias = 3;
}

message TotalHits {
int64 value = 1;
Relation relation = 2;

enum Relation {
EQUAL_TO = 0;
GREATER_THAN_OR_EQUAL_TO = 1;
}
}
Original file line number Diff line number Diff line change
@@ -26,7 +26,7 @@ message ShardSearchRequest {
bool allowPartialSearchResults = 9;
repeated string indexRoutings = 10;
string preference = 11;
bytes scroll = 12;
Scroll scroll = 12;
int64 nowInMillis = 13;
optional string clusterAlias = 14;
optional ShardSearchContextId readerId = 15;
@@ -53,6 +53,10 @@ message ShardId {
string indexUUID = 4;
}

message Scroll {
string keepAlive = 1;
}

message OriginalIndices {
repeated string indices = 1;
IndicesOptions indicesOptions = 2;