diff --git a/server/src/main/java/org/opensearch/grpc/services/search/SearchRequestBodyProtoHelper.java b/server/src/main/java/org/opensearch/grpc/services/search/SearchRequestBodyProtoHelper.java index 1b29655f5ea70..2aacde68032e6 100644 --- a/server/src/main/java/org/opensearch/grpc/services/search/SearchRequestBodyProtoHelper.java +++ b/server/src/main/java/org/opensearch/grpc/services/search/SearchRequestBodyProtoHelper.java @@ -8,6 +8,8 @@ package org.opensearch.grpc.services.search; +import org.opensearch.index.query.MatchAllQueryBuilder; + public class SearchRequestBodyProtoHelper { public static org.opensearch.search.builder.SearchSourceBuilder searchSourceBuilderFromProto(opensearch.proto.SearchRequest searchRequestProto, opensearch.proto.SearchRequestBody searchRequestBodyProto) { org.opensearch.search.builder.SearchSourceBuilder sourceBuilder = new org.opensearch.search.builder.SearchSourceBuilder(); @@ -25,8 +27,8 @@ public static org.opensearch.search.builder.SearchSourceBuilder searchSourceBuil } */ - // TODO: POC only implements match all query - + // TODO: Support more queries + sourceBuilder.query(new MatchAllQueryBuilder()); return sourceBuilder; } } diff --git a/server/src/main/java/org/opensearch/grpc/services/search/SearchRequestProtoHelper.java b/server/src/main/java/org/opensearch/grpc/services/search/SearchRequestProtoHelper.java index 909f66bda88ef..6553ee3831f3e 100644 --- a/server/src/main/java/org/opensearch/grpc/services/search/SearchRequestProtoHelper.java +++ b/server/src/main/java/org/opensearch/grpc/services/search/SearchRequestProtoHelper.java @@ -16,6 +16,7 @@ import static org.opensearch.action.search.SearchRequest.DEFAULT_INDICES_OPTIONS; import static org.opensearch.common.unit.TimeValue.parseTimeValue; +import static org.opensearch.grpc.services.search.SearchRequestBodyProtoHelper.searchSourceBuilderFromProto; public class SearchRequestProtoHelper { @@ -27,12 +28,21 @@ public static org.opensearch.action.search.SearchRequest searchRequestFromProto( //[optional] Whether to include the _source field in the response. //optional SourceConfigParam source = 1; + if (proto.hasSource()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] A list of source fields to exclude from the response. You can also use this parameter to exclude fields from the subset specified in `source_includes` query parameter. If the `source` parameter is `false`, this parameter is ignored. //repeated string source_excludes = 2; + if (proto.getSourceExcludesCount() > 0) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] A list of source fields to include in the response. If this parameter is specified, only these source fields are returned. You can exclude fields from this subset using the `source_excludes` query parameter. If the `source` parameter is `false`, this parameter is ignored. //repeated string source_includes = 3 ; + if (proto.getSourceIncludesCount() > 0) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } /* [optional] Whether to ignore wildcards that don't match any indexes. Default is true. @@ -61,9 +71,15 @@ public static org.opensearch.action.search.SearchRequest searchRequestFromProto( //[optional] Whether the update operation should include wildcard and prefix queries in the analysis. Default is false. //optional bool analyze_wildcard = 6; + if (proto.hasAnalyzeWildcard()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Analyzer to use for the query string. This parameter can only be used when the q query optional string parameter is specified. //optional string analyzer = 7; + if (proto.hasAnalyzer()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] How many shard results to reduce on a node. Default is 512. //optional int32 batched_reduce_size = 8; @@ -80,24 +96,45 @@ public static org.opensearch.action.search.SearchRequest searchRequestFromProto( //[optional] Indicates whether the default operator for a string query should be AND or OR. Default is OR. //optional Operator default_operator = 11; + if (proto.hasDefaultOperator()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] The default field in case a field prefix is not provided in the query string. //optional string df = 12; + if (proto.hasDf()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] The fields that OpenSearch should return using their docvalue forms. //repeated string docvalue_fields = 13; + if (!proto.getDocvalueFieldsList().isEmpty()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Whether to return details about how OpenSearch computed the document's score. Default is false. //optional bool explain = 15; + if (proto.hasExplain()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] The starting index to search from. Default is 0. //optional int32 from = 16; + if (proto.hasFrom()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Whether to return scores with named queries. Default is false. //optional bool include_named_queries_score = 19; + if (proto.hasIncludeNamedQueriesScore()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Specifies whether OpenSearch should accept requests if queries have format errors (for example, querying a text field for an integer). Default is false. //optional bool lenient = 20; + if (proto.hasLenient()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Numbers of concurrent shard requests this request should execute on each node. Default is 5. //optional int32 max_concurrent_shard_requests = 21; @@ -117,6 +154,9 @@ public static org.opensearch.action.search.SearchRequest searchRequestFromProto( //[optional] Query in the Lucene query string syntax using query parameter search. //optional string q = 25; + if (proto.hasQ()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Specifies whether OpenSearch should use the request cache. Default is whether it's enabled in the index's settings. //optional bool request_cache = 26; @@ -124,6 +164,7 @@ public static org.opensearch.action.search.SearchRequest searchRequestFromProto( //[optional] Indicates whether to return hits.total as an integer. Returns an object otherwise. Default is false. //optional bool rest_total_hits_as_int = 27; + checkRestTotalHits(proto.getRestTotalHitsAsInt(), searchReq); // set trackTotalHits //[optional] Value used to route the update by query operation to a specific shard. //repeated string routing = 28; @@ -148,52 +189,97 @@ public static org.opensearch.action.search.SearchRequest searchRequestFromProto( //[optional] Whether to return sequence number and primary term of the last operation of each document hit. //optional bool seq_no_primary_term = 32; + if (proto.hasSeqNoPrimaryTerm()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Number of results to include in the response. //optional int32 size = 33; + if (proto.hasSize()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] A list of : pairs to sort by. //repeated string sort = 34; + if (proto.getSortCount() > 0) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Value to associate with the request for additional logging. //repeated string stats = 35; + if (proto.getStatsCount() > 0) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Whether the get operation should retrieve fields stored in the index. Default is false. //repeated string stored_fields = 36; + if (proto.getStoredFieldsCount() > 0) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Fields OpenSearch can use to look for similar terms. //optional string suggest_field = 37; + if (proto.hasSuggestField()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] The mode to use when searching. This parameter can only be used when the `suggest_field` and `suggest_text` query optional string parameters are specified. //optional SuggestMode suggest_mode = 38; + if (proto.hasSuggestMode()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Number of suggestions to return. //optional int32 suggest_size = 39; + if (proto.hasSuggestSize()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] The source that suggestions should be based off of. //optional string suggest_text = 40; + if (proto.hasSuggestText()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] The maximum number of documents OpenSearch should process before terminating the request. Default is 0. //optional int32 terminate_after = 41; + if (proto.hasTerminateAfter()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Period of time to wait for a response from active shards. Default is 1m. //optional string timeout = 42; + if (proto.hasTimeout()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Whether to return document scores. Default is false. //optional bool track_scores = 43; + if (proto.hasTrackScores()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Whether to return how many documents matched the query. //optional TrackHits track_total_hits = 44; - checkRestTotalHits(proto.getRestTotalHitsAsInt(), searchReq); // set trackTotalHits + if (proto.hasTrackTotalHits()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Whether returned aggregations and suggested terms should include their types in the response. Default is true. //optional bool typed_keys = 45; + if (proto.hasTypedKeys()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Whether to include the document version as a match. Default is false //optional bool version = 46; + if (proto.hasVersion()) { // TODO + throw new UnsupportedOperationException("opensearch.proto.SearchRequest not supported"); + } //[optional] Search Request body //optional SearchRequestBody request_body = 47; + searchSourceBuilderFromProto(proto, proto.getRequestBody()); return searchReq; }