-
Notifications
You must be signed in to change notification settings - Fork 10
Search API Examples
Jorge Padilla edited this page Feb 16, 2024
·
6 revisions
Sample search API queries using curl. For additional information check the topic Search Query API
- Create a route to the search API on your cluster and gather the URL and Kubernetes user token.
oc create route passthrough search-api --service=search-search-api -n open-cluster-management export URL="https://$(oc get route search-api -n open-cluster-management | awk 'NR==2' |awk '{print $2;}')/searchapi/graphql" export TOKEN=$(oc whoami -t)
- (Optional) The samples below use jq to format the JSON response
curl --insecure --location \
--request POST $URL \
--header "Authorization: Bearer $TOKEN" --header 'Content-Type: application/json' \
--data-raw '{"query":"query q($input: [SearchInput]) { search(input: $input) { count items } }","variables":{"input":[{"keywords":[],"filters":[{"property":"label","values":["app=search"]}], "limit":100}]}}' | jq
curl --insecure --location \
--request POST $URL \
--header "Authorization: Bearer $TOKEN" --header 'Content-Type: application/json' \
--data-raw '{"query":"query q($input: [SearchInput]) { search(input: $input) { related { kind count items } } }","variables":{"input":[{"keywords":[],"filters":[{"property":"label","values":["app=search"]}], "limit":100}]}}' | jq
curl --insecure --location \
--request POST $URL \
--header "Authorization: Bearer $TOKEN" --header 'Content-Type: application/json' \
--data-raw '{"query":"query q($input: [SearchInput]) { search(input: $input) { related { kind count items } } }","variables":{"input":[{"relatedKinds":["Secret"], "keywords":[],"filters":[{"property":"label","values":["app=search"]}], "limit":100}]}}' | jq
curl --insecure --location \
--request POST $URL \
--header "Authorization: Bearer $TOKEN" --header 'Content-Type: application/json' \
--data-raw '{"query":"query searchResultItems($input: [SearchInput]) { searchResult: search(input: $input) { count items } }","variables":{"input":[{"keywords":[],"filters":[{"property":"kind","values":["Pod"]}],"limit":100}]}}' | jq
curl --insecure --location \
--request POST $URL \
--header "Authorization: Bearer $TOKEN" --header 'Content-Type: application/json' \
--data-raw '{"query":"query searchResultItems($input: [SearchInput]) {\n searchResult: search(input: $input) {\n items\n }\n }\n","variables":{"input":[{"keywords":["apple"],"filters":[],"limit":100}]}}' | jq
curl --insecure --location \
--request POST $URL \
--header "Authorization: Bearer $TOKEN" --header 'Content-Type: application/json' \
--data-raw '{"query":"query searchResultItems($input: [SearchInput]) {\n searchResult: search(input: $input) {\n items\n }\n }\n","variables":{"input":[{"keywords":[],"filters":[{"property":"kind","values":["ConfigMap"]}],"limit":100}]}}' | jq