The Search API
Programmatic retrieval with a typed client
You'll be able to
- Issue a Search API query with filters and paging from a typed client
- Read titles, URLs, and snippets from the typed response
Read first
Day 3 Lab
- Build a Search API request: a query string plus a
page_size. - Add a facet filter to scope by datasource (e.g. only Drive).
- Run it and read each result's title, URL, and snippet from the typed response.
- Confirm results respect the caller's permissions β same filtering as the UI.
Working Example: A Filtered Search Query
The Search API takes a query plus optional facet filters and returns typed results with snippets that show why each matched. Verified against api_clients.
import os
from glean import Glean
client = Glean(
instance=os.environ["GLEAN_INSTANCE"],
api_token=os.environ["GLEAN_API_TOKEN"],
actas_user=os.environ["END_USER_EMAIL"],
)
response = client.client.search.query(
query="incident runbook",
page_size=10,
request_options={
"facet_filters": [
{"field_name": "datasource", "values": [{"value": "gdrive"}]}
]
},
)
for r in response.results:
print(r.title)
print(" ", r.url)
print(" snippet:", r.snippets[0].text if r.snippets else "(none)")
The snippets field is the "why it matched" β the same matched text the UI highlights. Verified against api_clients.
Check for understanding
Which response field tells you WHY a result matched, and where do you set a datasource filter?
Check yourself
1. Which set of languages does Glean ship typed Developer Platform clients for?
2. Why does a user-scoped token return different results for two different users running the same query?
3. In a Chat API response, what do the citations tell you?
4. You need to make 10,000 support tickets searchable in Glean. Which API do you use?
5. When pushing documents through the Indexing API, why must you include permission metadata?
In 10 seconds
βThe Search API is the search box as code. Pass a query, add facet filters, page through typed results β and the per-user token means the API returns exactly what that user could find in the UI.β
The Chat API