Skip to content

Commit

Permalink
Throw exception on unsupported proto inputs. Hack match all query int…
Browse files Browse the repository at this point in the history
…o all request bodies.

Signed-off-by: Finn Carroll <[email protected]>
  • Loading branch information
finnegancarroll committed Nov 23, 2024
1 parent 8e31b46 commit 3b0824d
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 <source> 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 <source_excludes> 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 <source_includes> not supported");
}

/*
[optional] Whether to ignore wildcards that don't match any indexes. Default is true.
Expand Down Expand Up @@ -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 <analyze_wildcard> 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 <analyzer> not supported");
}

//[optional] How many shard results to reduce on a node. Default is 512.
//optional int32 batched_reduce_size = 8;
Expand All @@ -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 <default_operator> 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 <df> 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 <docvalue_fields> 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 <explain> 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 <from> 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 <include_named_queries_score> 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 <lenient> 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;
Expand All @@ -117,13 +154,17 @@ 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 <q> 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;
searchReq.requestCache(proto.getRequestCache());

//[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;
Expand All @@ -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 <seq_no_primary_term> 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 <size> not supported");
}

//[optional] A list of <field> : <direction> pairs to sort by.
//repeated string sort = 34;
if (proto.getSortCount() > 0) { // TODO
throw new UnsupportedOperationException("opensearch.proto.SearchRequest <sort> 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 <stats> 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 <stored_fields> 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 <suggest_field> 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 <suggest_mode> not supported");
}

//[optional] Number of suggestions to return.
//optional int32 suggest_size = 39;
if (proto.hasSuggestSize()) { // TODO
throw new UnsupportedOperationException("opensearch.proto.SearchRequest <suggest_size> 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 <suggest_text> 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 <terminate_after> 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 <timeout> 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 <track_scores> 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 <track_total_hits> 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 <typed_keys> 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 <version> not supported");
}

//[optional] Search Request body
//optional SearchRequestBody request_body = 47;
searchSourceBuilderFromProto(proto, proto.getRequestBody());

return searchReq;
}
Expand Down

0 comments on commit 3b0824d

Please sign in to comment.