-
Notifications
You must be signed in to change notification settings - Fork 2.3k
[GRPC] SearchService and Search GRPC endpoint v1 #17830
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b4fcede
[GRPC] SearchService and Search GRPC endpoint v1
karenyrx 3354776
more tests
karenyrx d685fdf
empty commit to retrigger flaky test CI
karenyrx 52285b2
address comments
karenyrx ada3465
make BulkRequestActionListener observer final too
karenyrx 5bb04e1
empty commit for CI
karenyrx 148f712
Merge branch 'main' into search-4
andrross 1a98708
fix floating javadocs, add null checks, restrict public method visibl…
karenyrx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| a29095657b4a0f9b59659d71e7e540e9b07fd044 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...main/java/org/opensearch/plugin/transport/grpc/listeners/SearchRequestActionListener.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.plugin.transport.grpc.listeners; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.opensearch.action.search.SearchResponse; | ||
| import org.opensearch.core.action.ActionListener; | ||
| import org.opensearch.plugin.transport.grpc.proto.response.search.SearchResponseProtoUtils; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import io.grpc.stub.StreamObserver; | ||
|
|
||
| /** | ||
| * Listener for search request execution completion, handling successful and failure scenarios. | ||
| */ | ||
| public class SearchRequestActionListener implements ActionListener<SearchResponse> { | ||
| private static final Logger logger = LogManager.getLogger(SearchRequestActionListener.class); | ||
|
|
||
| private final StreamObserver<org.opensearch.protobufs.SearchResponse> responseObserver; | ||
|
|
||
| /** | ||
| * Constructs a new SearchRequestActionListener. | ||
| * | ||
| * @param responseObserver the gRPC stream observer to send the search response to | ||
| */ | ||
| public SearchRequestActionListener(StreamObserver<org.opensearch.protobufs.SearchResponse> responseObserver) { | ||
| super(); | ||
| this.responseObserver = responseObserver; | ||
| } | ||
|
|
||
| @Override | ||
| public void onResponse(SearchResponse response) { | ||
| // Search execution succeeded. Convert the opensearch internal response to protobuf | ||
| try { | ||
| org.opensearch.protobufs.SearchResponse protoResponse = SearchResponseProtoUtils.toProto(response); | ||
| responseObserver.onNext(protoResponse); | ||
| responseObserver.onCompleted(); | ||
| } catch (RuntimeException | IOException e) { | ||
| responseObserver.onError(e); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void onFailure(Exception e) { | ||
| logger.error("SearchRequestActionListener failed to process search request:" + e.getMessage()); | ||
| responseObserver.onError(e); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../org/opensearch/plugin/transport/grpc/proto/request/search/CollapseBuilderProtoUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
| package org.opensearch.plugin.transport.grpc.proto.request.search; | ||
|
|
||
| import org.opensearch.core.xcontent.XContentParser; | ||
| import org.opensearch.protobufs.FieldCollapse; | ||
| import org.opensearch.search.collapse.CollapseBuilder; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| /** | ||
| * Utility class for converting CollapseBuilder Protocol Buffers to objects | ||
| * | ||
| */ | ||
| public class CollapseBuilderProtoUtils { | ||
|
|
||
| private CollapseBuilderProtoUtils() { | ||
| // Utility class, no instances | ||
| } | ||
|
|
||
| /** | ||
| * Similar to {@link CollapseBuilder#fromXContent(XContentParser)} | ||
| * | ||
| * @param collapseProto | ||
| */ | ||
|
|
||
karenyrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static CollapseBuilder fromProto(FieldCollapse collapseProto) throws IOException { | ||
| CollapseBuilder collapseBuilder = new CollapseBuilder(collapseProto.getField()); | ||
|
|
||
| if (collapseProto.hasMaxConcurrentGroupSearches()) { | ||
| collapseBuilder.setMaxConcurrentGroupRequests(collapseProto.getMaxConcurrentGroupSearches()); | ||
| } | ||
| if (collapseProto.getInnerHitsCount() > 0) { | ||
| collapseBuilder.setInnerHits(InnerHitsBuilderProtoUtils.fromProto(collapseProto.getInnerHitsList())); | ||
| } | ||
|
|
||
| return collapseBuilder; | ||
| } | ||
|
|
||
| } | ||
35 changes: 35 additions & 0 deletions
35
...a/org/opensearch/plugin/transport/grpc/proto/request/search/FieldAndFormatProtoUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
| package org.opensearch.plugin.transport.grpc.proto.request.search; | ||
|
|
||
| import org.opensearch.core.xcontent.XContentParser; | ||
| import org.opensearch.search.fetch.subphase.FieldAndFormat; | ||
|
|
||
| /** | ||
| * Utility class for converting SearchSourceBuilder Protocol Buffers to objects | ||
| * | ||
| */ | ||
| public class FieldAndFormatProtoUtils { | ||
|
|
||
| private FieldAndFormatProtoUtils() { | ||
| // Utility class, no instances | ||
| } | ||
|
|
||
| /** | ||
| * Similar to {@link FieldAndFormat#fromXContent(XContentParser)} | ||
| * | ||
| * @param fieldAndFormatProto | ||
| */ | ||
|
|
||
karenyrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static FieldAndFormat fromProto(org.opensearch.protobufs.FieldAndFormat fieldAndFormatProto) { | ||
|
|
||
| // TODO how is this field used? | ||
| // fieldAndFormatProto.getIncludeUnmapped(); | ||
| return new FieldAndFormat(fieldAndFormatProto.getField(), fieldAndFormatProto.getFormat()); | ||
| } | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
...org/opensearch/plugin/transport/grpc/proto/request/search/HighlightBuilderProtoUtils.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
| package org.opensearch.plugin.transport.grpc.proto.request.search; | ||
|
|
||
| import org.opensearch.core.xcontent.XContentParser; | ||
| import org.opensearch.protobufs.Highlight; | ||
| import org.opensearch.search.fetch.subphase.highlight.HighlightBuilder; | ||
|
|
||
| /** | ||
| * Utility class for converting Highlight Protocol Buffers to objects | ||
| * | ||
| */ | ||
| public class HighlightBuilderProtoUtils { | ||
|
|
||
| private HighlightBuilderProtoUtils() { | ||
| // Utility class, no instances | ||
| } | ||
|
|
||
| /** | ||
| * Similar to {@link HighlightBuilder#fromXContent(XContentParser)} | ||
| * | ||
| * @param highlightProto | ||
| */ | ||
|
|
||
karenyrx marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| public static HighlightBuilder fromProto(Highlight highlightProto) { | ||
|
|
||
| throw new UnsupportedOperationException("highlight not supported yet"); | ||
|
|
||
| /* | ||
| HighlightBuilder highlightBuilder = new HighlightBuilder(); | ||
| // TODO populate highlightBuilder | ||
| return highlightBuilder; | ||
| */ | ||
|
|
||
| } | ||
|
|
||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If fetchSource is explicitly set to false here
fetchSource != nullis true. Should we default fetchSource to false and change the condition toif (fetchSource || ...?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the equivalent REST-side implementation: https://github.com/opensearch-project/OpenSearch/blob/main/server/src/main/java/org/opensearch/search/fetch/subphase/FetchSourceContext.java#L135 which also does the same check. Following this, I think this GRPC code is accurate?