-
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 all 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); | ||
|
Check warning on line 47 in plugins/transport-grpc/src/main/java/org/opensearch/plugin/transport/grpc/listeners/SearchRequestActionListener.java
|
||
| } | ||
| } | ||
|
|
||
| @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
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
51 changes: 51 additions & 0 deletions
51
.../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,51 @@ | ||
| /* | ||
| * 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 OpenSearch objects. | ||
| * This class provides methods to transform Protocol Buffer representations of field collapse | ||
| * specifications into their corresponding OpenSearch CollapseBuilder implementations for | ||
| * search result field collapsing and grouping. | ||
| */ | ||
| public class CollapseBuilderProtoUtils { | ||
|
|
||
| private CollapseBuilderProtoUtils() { | ||
| // Utility class, no instances | ||
| } | ||
|
|
||
| /** | ||
| * Converts a Protocol Buffer FieldCollapse to an OpenSearch CollapseBuilder. | ||
| * Similar to {@link CollapseBuilder#fromXContent(XContentParser)}, this method | ||
| * parses the Protocol Buffer representation and creates a properly configured | ||
| * CollapseBuilder with the appropriate field, max concurrent group searches, | ||
| * and inner hits settings. | ||
| * | ||
| * @param collapseProto The Protocol Buffer FieldCollapse to convert | ||
| * @return A configured CollapseBuilder instance | ||
| * @throws IOException if there's an error during parsing or conversion | ||
| */ | ||
| protected 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; | ||
| } | ||
| } |
39 changes: 39 additions & 0 deletions
39
...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,39 @@ | ||
| /* | ||
| * 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 FieldAndFormat Protocol Buffers to OpenSearch objects. | ||
| * This class provides methods to transform Protocol Buffer representations of field and format | ||
| * specifications into their corresponding OpenSearch FieldAndFormat implementations for search operations. | ||
| */ | ||
| public class FieldAndFormatProtoUtils { | ||
|
|
||
| private FieldAndFormatProtoUtils() { | ||
| // Utility class, no instances | ||
| } | ||
|
|
||
| /** | ||
| * Converts a Protocol Buffer FieldAndFormat to an OpenSearch FieldAndFormat object. | ||
| * Similar to {@link FieldAndFormat#fromXContent(XContentParser)}, this method | ||
| * parses the Protocol Buffer representation and creates a properly configured | ||
| * FieldAndFormat with the appropriate field name and format settings. | ||
| * | ||
| * @param fieldAndFormatProto The Protocol Buffer FieldAndFormat to convert | ||
| * @return A configured FieldAndFormat instance | ||
| */ | ||
| protected static FieldAndFormat fromProto(org.opensearch.protobufs.FieldAndFormat fieldAndFormatProto) { | ||
|
|
||
| // TODO how is this field used? | ||
| // fieldAndFormatProto.getIncludeUnmapped(); | ||
| return new FieldAndFormat(fieldAndFormatProto.getField(), fieldAndFormatProto.getFormat()); | ||
| } | ||
| } |
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?