Skip to content

Indexing API Cmdlets

The Indexing API cmdlets in glean-powershell provide a PowerShell interface for managing Glean data sources, documents, users, groups, and permissions via the Indexing API. These cmdlets are generated wrappers that map PowerShell parameters to the JSON request bodies required by the Glean REST API, handling serialization, HTTP invocation, and response parsing.

The Add-GleanDatasource cmdlet allows users to add or update a custom datasource and its schema 1. It accepts a wide range of parameters that map directly to the request body fields, such as Name (the unique identifier), DisplayName, DatasourceCategory, and UrlRegex. Configuration options include IconUrl, IconDarkUrl, HomeUrl, and CrawlerSeedUrls for web crawling datasources. Advanced settings allow for URL and title canonicalization via CanonicalizingURLRegex and CanonicalizingTitleRegex, as well as redlisting titles with RedlistTitleRegex. The cmdlet also supports configuring Quicklinks, RenderConfigPreset, Aliases, and identity-related settings like IdentityDatasourceName and ProductAccessGroup. For non-idempotent operations, the RetryUnsafe switch permits retries on HTTP 429/503 errors.

Single document indexing is handled by Add-GleanDocument, which adds a document to the index or updates an existing one 2. This cmdlet requires a Document hashtable and optionally accepts a Version for optimistic concurrency control. For bulk operations, Add-GleanDocumentIndex adds or updates multiple documents in the index 3. It requires a Datasource name and a Documents array, and optionally accepts an UploadId to track the batch. Both document indexing cmdlets support a Body parameter for passing the full request body verbatim, which is useful for complex nested structures 2 3.

All indexing cmdlets follow a consistent internal structure. They define parameters in a Fields parameter set and a Body parameter set 1 2 3. In the process block, they construct a hashtable $__invoke containing the API name (indexing), HTTP method (POST), and specific path (e.g., /adddatasource, /indexdocument, /indexdocuments) 4 2 3. The cmdlet then calls Invoke-GleanRequest with this hashtable, passing the constructed body and any specified switches like RetryUnsafe or Raw 4 2 3.