← Glean-ia-acs Β· Day 45 of 56
Level 400 β€” Builder Β· APIs30 minNIST MAP

The Search API

Programmatic retrieval with a typed client

You'll be able to

Read first

Day 3 Lab

  1. Build a Search API request: a query string plus a page_size.
  2. Add a facet filter to scope by datasource (e.g. only Drive).
  3. Run it and read each result's title, URL, and snippet from the typed response.
  4. 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

Pick an answer β€” you'll see if it's right and why.

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?

Pass threshold 80% Β· week 7 quiz

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.”

Next Β· Week 7 Day 4
The Chat API