Filters are a powerful tool to narrow down your search results. We support filters that are generalized to every document, as well as filters that are specific to different datasources.

This guide will focus on our general filters and how to utilize them.

How to Use

In order to filter search results to show documents that match certain fields via the /search REST API, you need to construct a list of facetFilter objects and pass it into the requestOptions object.

Each facetFilter object has the following relevant fields:

Field NameDescription
fieldNamethe name of the field we are filtering by (eg “from” to facet by user, “type” for document type, etc). fieldName should be unique in the list of facetFilter objects.
valuesa list of facetFilterValue objects. All values are OR’d between the same field name (we AND between different field names).

A facetFilterValue object has the following relevant fields:

Field NameDescription
valuestring value that results are being filtered to.
relationTypecan take on the values below:

Basic Example

To filter to only the document type pdf search results, you would send the following in the facetFilter field. This is the equivalent of adding “type:pdf” to your search query.

[
  {
    "fieldName": "type",
    "values": [
      {
        "relationType": "EQUALS",
        "value": "pdf"
      }
    ]
  }
]

Universal Field Names

Topbar Facet Field Names

Field NameDescription
last_updated_atFilter by document last updated at
fromFilter by user who created/modified the document. Supports special value “me” for the current user
myFilter by documents that are in the current user’s history. Supports special value “history”
collectionFilter by collection name
hasFilter by whether a document has a specific field. Supports special value “golink” to filter by documents with a golink
typeFilter by document type

Entity Field Names

Field NameDescription
businessunitFilter by business unit
cityFilter by city
countryFilter by country
industryFilter by industry
locationFilter by location
regionFilter by region
roletypeFilter by role type
startafterFilter by start date after
startbeforeFilter by start date before
stateFilter by state
titleFilter by title
reportstoFilter by reporting to

Exceptions to the basic example

Time filters

Time filters are the only exception to the rule. The fieldName is always “last_updated_at”, and we use different relationTypes to specify different time ranges.

We support 2 types of values: specific dates and special values.

Specific dates

Use the “GT” and “LT” relationTypes to specify a date range. The ranges can also be open-ended (only include a GT or an LT). Each date value should be in the form YYYY-MM-DD passed in as a string. Note that when using GT and LT, the values are noninclusive (eg using {relationType=”GT”, value=”2023-06-17”} will include dates from 2023-06-18 and later).

All dates provided will begin with the “start of the day” (12:00 am). Dates will end at the end of the day (11:59:59 pm).

Closed date range example for filtering to documents from dates 6/16, 6/17, 6/18, 6/19:

[
   {
      "fieldName":"last_updated_at",
      "values":[
         {
            "relationType":"GT",
            "value":"2023-06-15"
         },
         {
            "relationType":"LT",
            "value":"2023-06-20"
         }
      ]
   }
]

Open date range example for filtering to documents from dates 6/11 onwards:

[
   {
      "fieldName":"last_updated_at",
      "values":[
         {
            "relationType":"GT",
            "value":"2023-06-10"
         },
      ]
   }
]

Special Values

For special values, we allow the values past_day, past_week, past_month, yesterday, today, past_n_days, past_n_weeks, past_n_months, past_n_years for the relation type EQUALS, where n is a number, ie 5 in past_5_days. For all past_ prefixed values, we also support the last_ prefix, they mean the same thing (ie last_week is a viable substitute for past_week).

We allow the values past_day, past_week, past_month, yesterday,today for the relation type LT.

We allow the values yesterday for the relation type GT.

If you pass in an invalid special value, you will get an 422 error letting you know you have an invalid operator. Invalid special values for time filters are the only case in which a 422 error is returned.

If you are used to using operators and values in the query string, here are some examples of translations of query string value to REST API value.

Sample:

updated:today becomes

[{fieldName: "last_updated_at", values: [{relationType: "EQUALS", value: "today"}]}]

before:past_week becomes

[{fieldName: "last_updated_at", values: [{relationType: "LT", value: "past_week"}]}]

after:yesterday becomes

[{fieldName: "last_updated_at", values: [{relationType: "GT", value: "yesterday"}]}]

Timezone considerations

We factor in user’s timezone for all queries except when you use the value past_week, past_year, past_month and past_day with the relationType EQUALS. (these are handled by built-in elastic date aggregation that doesn’t account for timezone).

History filter

my: facet will only ever have the value “history”. It filters to show only documents the user has viewed before. The object always looks like this:

{fieldName: "suggested", groupName: "", values: [{relationType: "EQUALS", value: "my history"}]}

From filter (or any user filter):

If you would like to specify a specific user, for example, if there are 2 people with the same name, “User one”, you can specify which one you mean by using the email address they authenticated with Glean as the value . IE user@glean.com and userone@glean.com would facet by different “User One”s even if they have the same name.

Sample query:

from:"User one" updated:today type:document
requestOptions.facetFilters:
[{ "fieldName": "from",
    "values": [ {
        "relationType": "EQUALS",
        "value": "userone@glean.com"
      }] },
  {
    "fieldName": "last_updated_at",
    "values": [{
        "relationType": "EQUALS",
        "value": "today"
      }] },
  {
    "fieldName": "type",
    "values": [{
        "relationType": "EQUALS",
        "value": "document"
      }]}
]