POST
/
rest
/
api
/
v1
/
search
from glean.api_client import Glean, models
from glean.api_client.utils import parse_datetime
import os


with Glean(
    api_token=os.getenv("GLEAN_API_TOKEN", ""),
    instance=os.getenv("GLEAN_INSTANCE", ""),
) as g_client:

    res = g_client.client.search.query(query="vacation policy", tracking_token="trackingToken", source_document=models.Document(
        container_document=models.Document(
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
        parent_document=models.Document(
            metadata=models.DocumentMetadata(
                datasource="datasource",
                object_type="Feature Request",
                container="container",
                parent_id="JIRA_EN-1337",
                mime_type="mimeType",
                document_id="documentId",
                create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
                author=models.Person(
                    name="name",
                    obfuscated_id="<id>",
                ),
                components=[
                    "Backend",
                    "Networking",
                ],
                status="[\"Done\"]",
                custom_data={
                    "someCustomField": models.CustomDataValue(),
                },
            ),
        ),
        metadata=models.DocumentMetadata(
            datasource="datasource",
            object_type="Feature Request",
            container="container",
            parent_id="JIRA_EN-1337",
            mime_type="mimeType",
            document_id="documentId",
            create_time=parse_datetime("2000-01-23T04:56:07.000Z"),
            update_time=parse_datetime("2000-01-23T04:56:07.000Z"),
            author=models.Person(
                name="name",
                obfuscated_id="<id>",
            ),
            components=[
                "Backend",
                "Networking",
            ],
            status="[\"Done\"]",
            custom_data={
                "someCustomField": models.CustomDataValue(),
            },
        ),
    ), page_size=10, max_snippet_size=400, input_details={
        "has_copy_paste": True,
    }, request_options=models.SearchRequestOptions(
        facet_filters=[
            models.FacetFilter(
                field_name="type",
                values=[
                    models.FacetFilterValue(
                        value="article",
                        relation_type=models.RelationType.EQUALS,
                    ),
                    models.FacetFilterValue(
                        value="document",
                        relation_type=models.RelationType.EQUALS,
                    ),
                ],
            ),
            models.FacetFilter(
                field_name="department",
                values=[
                    models.FacetFilterValue(
                        value="engineering",
                        relation_type=models.RelationType.EQUALS,
                    ),
                ],
            ),
        ],
        facet_bucket_size=939520,
    ), timeout_millis=5000, people=[
        models.Person(
            name="George Clooney",
            obfuscated_id="abc123",
        ),
    ])

    # Handle response
    print(res)
{
  "trackingToken": "trackingToken",
  "suggestedSpellCorrectedQuery": "suggestedSpellCorrectedQuery",
  "hasMoreResults": true,
  "errorInfo": {
    "errorMessages": [
      {
        "source": "gmail",
        "errorMessage": "invalid token"
      },
      {
        "source": "slack",
        "errorMessage": "expired token"
      }
    ]
  },
  "requestID": "5e345ae500ff0befa2b9d1a3ba0001737e7363696f312d323535323137000171756572792d656e64706f696e743a323032303031333074313830343032000100",
  "results": [
    {
      "snippets": [
        {
          "snippet": "snippet",
          "mimeType": "mimeType"
        }
      ],
      "metadata": {
        "container": "container",
        "createTime": "2000-01-23T04:56:07.000Z",
        "datasource": "datasource",
        "author": {
          "name": "name"
        },
        "documentId": "documentId",
        "updateTime": "2000-01-23T04:56:07.000Z",
        "mimeType": "mimeType",
        "objectType": "objectType"
      },
      "title": "title",
      "url": "https://www.example.com/"
    },
    {
      "snippets": [
        {
          "snippet": "snippet",
          "mimeType": "mimeType"
        }
      ],
      "metadata": {
        "container": "container",
        "createTime": "2000-01-23T04:56:07.000Z",
        "datasource": "datasource",
        "author": {
          "name": "name"
        },
        "documentId": "documentId",
        "updateTime": "2000-01-23T04:56:07.000Z",
        "mimeType": "mimeType",
        "objectType": "objectType"
      },
      "title": "title",
      "url": "https://www.example.com/"
    }
  ],
  "facetResults": [
    {
      "buckets": [
        {
          "percentage": 5,
          "count": 1,
          "value": {
            "stringValue": "stringValue",
            "integerValue": 5
          }
        },
        {
          "percentage": 5,
          "count": 1,
          "value": {
            "stringValue": "stringValue",
            "integerValue": 5
          }
        }
      ],
      "sourceName": "sourceName",
      "operatorName": "operatorName",
      "objectType": "objectType"
    },
    {
      "buckets": [
        {
          "percentage": 5,
          "count": 1,
          "value": {
            "stringValue": "stringValue",
            "integerValue": 5
          }
        },
        {
          "percentage": 5,
          "count": 1,
          "value": {
            "stringValue": "stringValue",
            "integerValue": 5
          }
        }
      ],
      "sourceName": "sourceName",
      "operatorName": "operatorName",
      "objectType": "objectType"
    }
  ],
  "rewrittenQuery": "rewrittenQuery",
  "rewrittenFacetFilters": [
    {
      "fieldName": "fieldName",
      "values": [
        "fieldValues",
        "fieldValues"
      ]
    },
    {
      "fieldName": "fieldName",
      "values": [
        "fieldValues",
        "fieldValues"
      ]
    }
  ]
}

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Body

application/json

Search request

The body is of type object.

Response

200
application/json

OK

The response is of type object.