Skip to content

[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 8 commits into from
Apr 9, 2025

Conversation

karenyrx
Copy link
Contributor

@karenyrx karenyrx commented Apr 8, 2025

Description

  1. Scaffold initial search service and search GRPC endpoint. Supports MatchAll, TermQuery, and MatchNone. TODOs are left in the code for supporting aggregations, suggest, ext, other more involved query types, etc.
  2. Bumps the opensearch-protobuf jar verson to 0.2.0 to add in more proto fixes for the Search endpoint.

Test Plan

  1. Unit tests
  2. Manual party testing with HTTP (ongoing). e.g.
    a) Send a MatchAll query with "size" parameter in both the URL parameters as well as request body.

grpcurl -import-path ~/OpenSearch -d @ -proto ~/OpenSearch/search_service.proto -plaintext localhost:9400 org.opensearch.protobufs.services.SearchService/Search <<EOM
{
  "size": "3",
  "source": {
    "bool_value": true
  },
  "request_body": {
    "query": {
      "match_all": {}
    },
    "size": 40
  }
}
EOM

{
  "responseBody": {
    "took": "6",
    "timedOut": false,
    "shards": {
      "successful": 3,
      "total": 3
    },
    "hits": {
      "total": {
        "totalHits": {
          "relation": "TOTAL_HITS_RELATION_EQ",
          "value": "1"
        }
      },
      "hits": [
        {
          "index": "my_index",
          "id": "2",
          "score": {
            "floatValue": 1
          },
          "source": "eyJkb2MiOnsieWVhciI6MjAxMywidGl0bGUiOiJSdXNoIn0sInRpbWVzdGFtcCI6IjIwMjUtMDQtMDhUMTI6MjQ6MzAuOTEyMjY5ODI5WiJ9",
          "metaFields": {
            "fields": {
              "_routing": {
                "listValue": {
                  "value": [
                    {
                      "string": "0"
                    }
                  ]
                }
              }
            }
          }
        }
      ],
      "maxScore": {
        "floatValue": 1
      }
    }
  }
}
curl -XGET "http://localhost:9200/_search?size=1&_source=true" -H 'Content-Type: application/json' -d '               
{
 "size": "40",
 "query": {
   "match_all": {}
 }
} ' | jq

{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "my_index",
        "_id": "2",
        "_score": 1,
        "_routing": "0",
        "_source": {
          "doc": {
            "year": 2013,
            "title": "Rush"
          },
          "timestamp": "2025-04-08T12:24:30.912269829Z"
        }
      }
    ]
  }
}

SearchRequest (same for both GRPC and HTTP)

SearchRequest{searchType=QUERY_THEN_FETCH, indices=[], indicesOptions=IndicesOptions[ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, expand_wildcards_hidden=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false, ignore_throttled=true], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=null, allowPartialSearchResults=null, localClusterAlias=null, getOrCreateAbsoluteStartMillis=-1, ccsMinimizeRoundtrips=true, source={"size":1,"query":{"match_all":{"boost":1.0}},"_source":{"includes":[],"excludes":[]}}, cancelAfterTimeInterval=null, pipeline=null, phaseTook=null}

b) TermQuery

grpcurl -import-path ~/OpenSearch -d @ -proto ~/OpenSearch/search_service.proto -plaintext localhost:9400 org.opensearch.protobufs.services.SearchService/Search <<EOM
{
 "request_body": [
    {
      "query": {
        "term": {
          "title": {
            "value": {
              "string_value": "Rush"
            },
	     "case_insensitive": true
          }
        }
      }
    }
  ],
  "index": "my_index"
}
EOM


{
  "responseBody": {
    "took": "64",
    "timedOut": false,
    "shards": {
      "successful": 1,
      "total": 1
    },
    "hits": {
      "total": {
        "totalHits": {
          "relation": "TOTAL_HITS_RELATION_EQ",
          "value": "1"
        }
      },
      "hits": [
        {
          "index": "my_index",
          "id": "3",
          "score": {
            "floatValue": 1
          },
          "source": "eyAidGl0bGUiOiAiUnVzaCIsICJ5ZWFyIjogMjAxM30=",
          "metaFields": {}
        }
      ],
      "maxScore": {
        "floatValue": 1
      }
    }
  }
}
curl -XGET "http://localhost:9200/my_index/_search" -H 'Content-Type: application/json' -d'
{
  "query": {
    "term": {
      "title": {
        "value": "Rush",
         "case_insensitive": true
      }
    }
  }
}' | jq

{
  "took": 4,
  "timed_out": false,
  "_shards": {
    "total": 3,
    "successful": 3,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "my_index",
        "_id": "3",
        "_score": 1,
        "_source": {
          "title": "Rush",
          "year": 2013
        }
      }
    ]
  }
}

SearchRequest (same for both GRPC and HTTP)

SearchRequest{searchType=QUERY_THEN_FETCH, indices=[my_index], indicesOptions=IndicesOptions[ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, expand_wildcards_hidden=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false, ignore_throttled=true], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=null, allowPartialSearchResults=null, localClusterAlias=null, getOrCreateAbsoluteStartMillis=-1, ccsMinimizeRoundtrips=true, source={"query":{"term":{"title":{"value":"Rush","case_insensitive":true,"boost":1.0}}}}, cancelAfterTimeInterval=null, pipeline=null, phaseTook=null}

c) MatchNone with source_includes field (compare POJOs not the response)


grpcurl -import-path ~/OpenSearch -d @ -proto ~/OpenSearch/search_service.proto -plaintext localhost:9400 org.opensearch.protobufs.services.SearchService/Search <<EOM
{
  "source": {
    "bool_value": true
  },
  "source_includes": [
    "title"
  ],
  "request_body": {
    "query": {
      "match_none": {}
    }
  }
}
EOM

{
  "responseBody": {
    "took": "5",
    "timedOut": false,
    "shards": {
      "successful": 1,
      "total": 1
    },
    "hits": {
      "total": {
        "totalHits": {
          "relation": "TOTAL_HITS_RELATION_EQ"
        }
      },
      "maxScore": {
        "nullValue": "NULL_VALUE_NULL"
      }
    }
  }
}
curl -XGET "http://localhost:9200/_search?_source=true&_source_includes=title" -H 'Content-Type: application/json' -d '
{
 "query": {
   "match_none": {}
 }
} ' | jq

{
  "took": 8,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 0,
      "relation": "eq"
    },
    "max_score": null,
    "hits": []
  }
}

SearchRequest (same for both GRPC and HTTP)

SearchRequest{searchType=QUERY_THEN_FETCH, indices=[], indicesOptions=IndicesOptions[ignore_unavailable=false, allow_no_indices=true, expand_wildcards_open=true, expand_wildcards_closed=false, expand_wildcards_hidden=false, allow_aliases_to_multiple_indices=true, forbid_closed_indices=true, ignore_aliases=false, ignore_throttled=true], routing='null', preference='null', requestCache=null, scroll=null, maxConcurrentShardRequests=0, batchedReduceSize=512, preFilterShardSize=null, allowPartialSearchResults=null, localClusterAlias=null, getOrCreateAbsoluteStartMillis=-1, ccsMinimizeRoundtrips=true, source={"query":{"match_none":{"boost":1.0}},"_source":{"includes":["title"],"excludes":[]}}, cancelAfterTimeInterval=null, pipeline=null, phaseTook=null}

The documents ingested 3 of the above tests were:

curl -vv -XPOST "http://localhost:9200/_bulk" -H 'Content-Type: application/json' -d'
{"index": {"_index": "my_index", "_id": "1"}}
{"title":"OpenSearch Basics", "price": "15"}


{"index": {"_index": "my_index", "_id": "2"}}
{"title":"OpenSearch Advanced", "author": "Cordelia M", "price": "28"}


{"index": {"_index": "my_index", "_id": "3"}}
{ "title": "Rush", "year": 2013}

'

Related Issues

#16783

Check List

  • Functionality includes testing.
  • API changes companion pull request created, if applicable.
  • Public documentation issue/PR created, if applicable.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Copy link
Contributor

github-actions bot commented Apr 8, 2025

❌ Gradle check result for 11b9615: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Apr 8, 2025

❌ Gradle check result for ddee102: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@karenyrx karenyrx force-pushed the search-4 branch 2 times, most recently from 4110529 to d950579 Compare April 8, 2025 12:03
Copy link
Contributor

github-actions bot commented Apr 8, 2025

❌ Gradle check result for d950579: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@karenyrx karenyrx force-pushed the search-4 branch 2 times, most recently from c9a59dd to 9d23b96 Compare April 8, 2025 15:56
Copy link
Contributor

github-actions bot commented Apr 8, 2025

❌ Gradle check result for 9d23b96: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Apr 8, 2025

❕ Gradle check result for 5ee1000: UNSTABLE

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

Copy link

codecov bot commented Apr 8, 2025

Codecov Report

Attention: Patch coverage is 80.96970% with 157 lines in your changes missing coverage. Please review.

Project coverage is 72.36%. Comparing base (7b6108b) to head (1a98708).
Report is 10 commits behind head on main.

Files with missing lines Patch % Lines
.../proto/request/search/SearchRequestProtoUtils.java 66.22% 35 Missing and 16 partials ⚠️
.../request/search/SearchSourceBuilderProtoUtils.java 81.63% 10 Missing and 8 partials ⚠️
...rpc/proto/response/search/SearchHitProtoUtils.java 80.55% 5 Missing and 9 partials ⚠️
...ponse/search/SearchResponseSectionsProtoUtils.java 18.18% 4 Missing and 5 partials ⚠️
...oto/request/search/InnerHitsBuilderProtoUtils.java 86.27% 3 Missing and 4 partials ⚠️
...c/proto/request/search/ProtoActionsProtoUtils.java 40.00% 1 Missing and 5 partials ⚠️
...t/search/query/AbstractQueryBuilderProtoUtils.java 25.00% 5 Missing and 1 partial ⚠️
...oto/request/search/sort/SortBuilderProtoUtils.java 62.50% 5 Missing and 1 partial ⚠️
...proto/request/search/IndicesOptionsProtoUtils.java 87.17% 0 Missing and 5 partials ⚠️
...rpc/proto/request/search/SearchTypeProtoUtils.java 28.57% 3 Missing and 2 partials ⚠️
... and 12 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main   #17830      +/-   ##
============================================
- Coverage     72.44%   72.36%   -0.09%     
- Complexity    66483    66727     +244     
============================================
  Files          5409     5450      +41     
  Lines        308282   309135     +853     
  Branches      44759    44998     +239     
============================================
+ Hits         223344   223703     +359     
- Misses        66608    67142     +534     
+ Partials      18330    18290      -40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

github-actions bot commented Apr 8, 2025

❌ Gradle check result for c8015b9: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Copy link
Contributor

github-actions bot commented Apr 8, 2025

❌ Gradle check result for 67bed87: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@andrross
Copy link
Member

andrross commented Apr 8, 2025

@karenyrx Can you rebase in the latest test fixes from main and fix the CHANGELOG conflict?

@karenyrx karenyrx marked this pull request as ready for review April 9, 2025 00:02
Copy link
Contributor

github-actions bot commented Apr 9, 2025

❌ Gradle check result for ada3465: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

Signed-off-by: Karen Xu <[email protected]>
Copy link
Contributor

github-actions bot commented Apr 9, 2025

❕ Gradle check result for 5bb04e1: UNSTABLE

Please review all flaky tests that succeeded after retry and create an issue if one does not already exist to track the flaky failure.

}

if (fetchSource != null || sourceIncludes != null || sourceExcludes != null) {
return new FetchSourceContext(fetchSource == null ? true : fetchSource, sourceIncludes, sourceExcludes);
Copy link
Contributor

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 != null is true. Should we default fetchSource to false and change the condition to if (fetchSource || ...?

Copy link
Contributor Author

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?

Copy link
Contributor

github-actions bot commented Apr 9, 2025

❌ Gradle check result for 148f712: FAILURE

Please examine the workflow log, locate, and copy-paste the failure(s) below, then iterate to green. Is the failure a flaky test unrelated to your change?

@karenyrx karenyrx force-pushed the search-4 branch 2 times, most recently from 164c00b to 6be7f0c Compare April 9, 2025 21:03
Copy link
Contributor

github-actions bot commented Apr 9, 2025

✅ Gradle check result for 1a98708: SUCCESS

@andrross andrross merged commit b7dca4a into opensearch-project:main Apr 9, 2025
31 of 32 checks passed
rgsriram pushed a commit to rgsriram/OpenSearch that referenced this pull request Apr 15, 2025
…17830)

Signed-off-by: Karen Xu <[email protected]>
Signed-off-by: Andrew Ross <[email protected]>
Co-authored-by: Andrew Ross <[email protected]>
Signed-off-by: Sriram Ganesh <[email protected]>
Harsh-87 pushed a commit to Harsh-87/OpenSearch that referenced this pull request May 7, 2025
…17830)

Signed-off-by: Karen Xu <[email protected]>
Signed-off-by: Andrew Ross <[email protected]>
Co-authored-by: Andrew Ross <[email protected]>
Signed-off-by: Harsh Kothari <[email protected]>
Harsh-87 pushed a commit to Harsh-87/OpenSearch that referenced this pull request May 7, 2025
…17830)

Signed-off-by: Karen Xu <[email protected]>
Signed-off-by: Andrew Ross <[email protected]>
Co-authored-by: Andrew Ross <[email protected]>
Signed-off-by: Harsh Kothari <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants