Filtering in the Aggregates API
This page describes the aggregate filter: the include and exclude lists in the request body of Create Aggregate, Create Aggregate Version and Update Aggregate. These decide which models and objects an aggregate contains. When you create a snapshot, the service evaluates these lists against the file versions you supply in that request. For what aggregates, aggregate versions, lineages and snapshots are, see Concepts.
Include and Exclude Overview
An aggregate records which models and objects to include, not copies of them. Each version of an aggregate holds that definition. You set it with the request body of Create Aggregate, Create Aggregate Version or Update Aggregate.
The request body has two lists:
include(required): 1 to 50 entries. Each entry selects models and objects to put in the aggregate.exclude(optional): up to 50 entries, in the same format. Each entry selects models and objects to leave out.
Includes are additive: every include entry is evaluated, and its matched objects are unioned into the result. Excludes are subtractive: the exclude pass runs after the includes and subtracts each exclude entry’s objects from the accumulated result.
Two edge-case behaviours follow from this:
- Exclude always wins. When an
includeentry and anexcludeentry select the same object, the object is left out. The exclude pass runs last, so an exclude match always removes the object from the result. - Exclude can’t act alone. An
excludeentry only subtracts objects that anincludeentry already selected. An object that no include entry matched is not in the aggregate to begin with, so an exclude entry matching it has no effect - and no exclude entry can add objects.
Each entry in either list is a filter entry, defined with the following properties:
| Attribute | Selects | Limits |
|---|---|---|
viewParts |
Specific views of a model. Each item gives a document lineage URN (urn) and a list of viewable names (viewParts). |
Up to 1,000 document lineage URNs. Up to 1,000 view parts for each. A viewable name can be at most 256 characters, can’t be empty or whitespace, and duplicates are removed silently. |
objectSets |
Specific objects, by object ID. Each item gives a document lineage URN (urn) and a list of integer object IDs (objects). |
Up to 1,000 document lineage URNs. Up to 10,000 objects for each. |
indexFilter |
Objects whose property values match a query. The query doesn’t name a lineage: on its own it runs against every model in the snapshot’s sources - the sourceVersions you supply to Create Aggregate Snapshot. If the entry also has viewParts or objectSets, it runs only against the lineages they name. See IndexFilter Query Language. |
No count limit, but the query has an upper size limit. See IndexFilter Query Language. |
disabled |
Nothing. A disabled entry stays in the definition but is ignored: when the service works out what the aggregate contains, it skips disabled entries. | Optional. Valid on entries in both include and exclude. |
id |
Nothing. An optional identifier you choose for the entry. It is stored with the aggregate version and returned in responses. | Optional. |
Each list you give must contain at least one item: an empty viewParts or objectSets array, or an empty objects list, is rejected.
The attributes of one entry combine with AND. For example, an entry with both viewParts and indexFilter selects, from the views it names, only the objects that match the property query.
Every document lineage URN, in include and in exclude, must identify a document in the project, and you must have permission to read it. The request fails otherwise.
Each new aggregate version stores its own filter. Once created, a version is immutable: to change what an aggregate contains, create a new version. When you create a snapshot, you choose which version of the aggregate to compile.
IndexFilter Query Language
A query has an upper size limit. Keep queries compact: a very large or deeply nested query can be rejected.
Rules that apply to every query
- Property names and string values look different. A plain string is read as a property name. To give a string value, put single quotes inside the JSON string:
"'Basic Wall'". Numbers and booleans don’t need quotes. - An array means OR. Each item in an array is a condition, and an object matches if it meets any of them.
- An object means AND. Each property of the object is a test that compares a property name with a value, and an object matches only if every test passes.
- Operators start with
$. An operator takes the form{ "$operator": <arguments> }. Logical operators ($and,$or,$not) take conditions. Comparison operators ($eq,$ne,$lt,$le,$gt,$ge,$like) take an array of exactly two expressions.$betweentakes exactly three.$intakes an array of one or more. - Operators can be nested.
Examples
Each example is a complete request body for Create Aggregate Version. Replace <property-id> with the identifier of a property in your model. All objects whose property equals one of two values (an array, so OR):
{
"include": [
{
"indexFilter": {
"filter": [
{ "s.props.<property-id>": "'<value>'" },
{ "s.props.<property-id>": "'<another-value>'" }
]
}
}
]
}
All objects that have a value for two properties (operators combined with $and):
{
"include": [
{
"indexFilter": {
"filter": {
"$and": [
{ "$notnull": "s.props.<property-id>" },
{ "$notnull": "s.props.<another-property-id>" }
]
}
}
}
]
}
All objects with a property greater than 300 (a comparison operator):
{
"include": [
{
"indexFilter": {
"filter": { "$gt": [ "s.props.<property-id>", 300 ] }
}
}
]
}
Operators
| Operators | Purpose |
|---|---|
$and, $or, $not |
Combine conditions. |
$eq, $ne, $lt, $le, $gt, $ge |
Compare two expressions. |
$like |
Match text against a pattern. |
$between |
Test whether a value falls between two others. |
$in |
Test whether a value equals any item in a list. |
$isnull, $notnull |
Test whether a property has no value, or has a value. |
$contains |
Test whether a value is present in an array property. |
$count |
Count the items in an array. |
$add, $sub, $mul, $div, $mod, $neg |
Arithmetic. |
$cat, $substring, $lower, $upper, $trim, $char_length, $to_string |
Text functions. |
$date_add, $date_diff, $extract, $utcnow, $to_timestamp |
Date and time functions. |
$sum, $avg, $min, $max |
Aggregate functions. See Aggregate Functions. |
$cast, $coalesce, $nullif, $case |
Type conversion and conditional values. |
$ref |
Reuse the query stored in another aggregate. See Refer to Another Aggregate’s Filter. |
Aggregate Functions
$sum, $avg, $min and $max are aggregate functions, not filters. They don’t select objects. They calculate one value from a property expression, evaluated across every object that matches the rest of the query, collapsing the result to a single row with a single value.
Because an aggregate function produces a value instead of a true-or-false answer, it can only appear in the $select clause of a Model Properties API query, never in a condition. An indexFilter is a condition, so a filter that uses one of these functions is rejected outright: the service doesn’t allow aggregate functions in filter conditions.
Example - a Model Properties API query that sums a property over the objects a condition selects:
{
"$where": { "$gt": [ "s.props.<property-id>", 100 ] },
"$select": { "totalArea": { "$sum": "s.props.<property-id>" } }
}
The query returns the single computed row. When no object matches the condition, the query still returns a row: a count over an empty set is 0, not “no rows”.
Refer to Another Aggregate’s Filter
A property query can reuse the index filter stored in another aggregate instead of repeating it. A $ref expression is an array of two elements: the filter to use, and a URN that says where it comes from. There are two forms.
The latest version. Give the referenced aggregate’s lineage URN, and null as the filter. The null stands for the index filter of the referenced aggregate’s latest version: when the filter is read, the latest version’s filter appears in its place. If the referenced aggregate is updated, you see the updated filter.
{
"include": [
{
"indexFilter": {
"filter": { "$ref": [ null, "urn:adsk.aggregate:lineage:<AGGREGATE_ID>" ] }
}
}
]
}
A specific version. Give a version URN, and the filter contents of that version. Unlike the latest-version form, the first element can’t be null: you must supply the referenced version’s filter, and the service checks that it matches that version’s filter exactly, so the expression can’t silently drift from what it points at:
{
"include": [
{
"indexFilter": {
"filter": { "$ref": [ { /* the referenced version's filter */ }, "urn:adsk.aggregate.version:<AGGREGATE_ID>?version=<VERSION>" ] }
}
}
]
}
Both forms of $ref read the index filter from a single entry of the referenced aggregate: its first include entry if the $ref appears inside your include list, or its first exclude entry if it appears inside your exclude list. If the referenced aggregate has more than one entry in that list, only the first is used - the rest are ignored.
A $ref can appear anywhere in a query. The referenced aggregate must be public, must have an index filter, can’t contain a $ref itself, and can’t be the aggregate you’re defining. Nor can you add a $ref to an aggregate that is itself referenced by others. The referenced aggregate can be in the same aggregate folder or at project level. A reference by lineage URN is tracked: the referenced aggregate can’t be deleted or made private while yours refers to it.