-
Notifications
You must be signed in to change notification settings - Fork 9
Search Query API
Jorge Padilla edited this page Jun 3, 2022
·
17 revisions
In this topic you will learn how to expose the search API with a route and how to use the API to resolve search queries.
The API is a GraphQL endpoint. You can use any client like curl or Postman. In this topic we'll use GraphQL Playground which is included with the search API deployment for development purposes.
At this point you should have installed the Search operator on your OpenShift cluster.
Use the following commands to enable the Playground client and create a route to access the API from outside of your cluster.
# 1. Pause the operator.
oc annotate search search-v2-operator -n open-cluster-management search-pause=true
# 2. Enable Playground on the API deployment.
oc set env deployment/search-api -n open-cluster-management PLAYGROUND_MODE=true
# 3. Create a route to access the API from outside the cluster.
oc create route passthrough search-api --service=search-search-api -n open-cluster-management
# 4. Open Playground from your browser.
PLAYGROUND_URL=https://$(oc get route search-api -o custom-columns=host:.spec.host --no-headers -n open-cluster-management)/playground
echo "Open Playground from your browser: $PLAYGROUND_URL"
The Search API is protected using Kubernetes authentication. You must obtain your OCP API token and add it to the request as the Authorization header.
- Get your API token from the OCP CLI:
oc whoami -t
- Get your API token from the OCP web console:
Go to https://oauth-openshift.apps.{{your-ocp-cluster-url}}/oauth/token/request
Add the header Authorization: "Bearer {{your-api-token}}"
.
- Search for deployments:
Query:Variables:query mySearch($input: [SearchInput]) { searchResult: search(input: $input) { items } }
Result:{"input":[ { "keywords":[], "filters":[ {"property":"kind","values":["Deployment"]}], "limit":10 } ]}