Search API Examples - stolostron/search-v2-operator GitHub Wiki

Sample search API queries using curl. For additional information check the topic Search Query API

Setup

  1. 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)
    
  2. (Optional) The samples below use jq to format the JSON response

Examples

Search for resources with the label "app=search", return count and items

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

Search for resources related to resources with the label "app=search"

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

Search for Secrets related to resources with the label "app=search"

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

Search for Pods

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

Search for any resource containing the keyword "apple"

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

Search for ConfigMaps

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