# ancestor in CQL: syntax and examples (Confluence)

URL: https://goingstellar.ro/reference/cql/ancestor-field/

ancestor returns every page that sits anywhere below a given page: children, grandchildren and deeper. You give it the numeric content id of the top page. It is the field to use for "everything in this handbook" or "all pages under the space home".

## Syntax

```
ancestor = <contentId>
ancestor in (<contentId>, <contentId>)
```

## Arguments

- `contentId` (optional: yes): The numeric id of the page, as it appears in the page URL. A title does not work.

## Works with

- Operators: =, !=, IN, NOT IN
- Functions: none listed in the documentation; recentlyViewedContent() ran with IN
- Not with: ~, !~, >, >=, <, <=

## Examples

```
ancestor = 32964613 AND type = page
```

Every page under a handbook, whatever its depth. Use it to count or audit a documentation tree. Run on Confluence Cloud on 2026-11-29.

```
ancestor = 32964613 AND title ~ "runbook"
```

Runbooks inside one section only, instead of across the whole space. Run on Confluence Cloud on 2026-11-29.

```
ancestor in (32964613, 655541) AND type = page
```

Pages under either of two parents in one query, written with IN. Run on Confluence Cloud on 2026-11-29.

```
ancestor = 655541 AND parent != 655541 AND type = page
```

Pages below the space home that are not its direct children, so the deeper levels only. Run on Confluence Cloud on 2026-11-29.

```
ancestor = 32964613 AND lastmodified >= startOfWeek() AND type = page ORDER BY lastmodified DESC
```

What changed this week inside one section, newest first. Run on Confluence Cloud on 2026-11-29.

```
ancestor not in (32964613) AND space = SD AND type = page
```

Every page of a space except the handbook subtree. Useful to exclude one area from a report. Run on Confluence Cloud on 2026-11-29.

## Pitfalls

- ancestor is wider than parent. With the handbook page 32964613 under the space home 655541, its child pages match both `ancestor = 32964613` and `ancestor = 655541`, but only `parent = 32964613` (checked on Confluence Cloud, November 2026).
- It only takes ids. `ancestor = "Company handbook"` fails with: Can't parse as a ContentId. An id that does not exist, such as `ancestor = 999999999`, does not fail: it returns no results.
- The page you name is not in its own result. `ancestor = 32964613 AND id = 32964613` returns nothing: the query lists what is below the handbook, not the handbook itself (checked on Confluence Cloud, November 2026).
- Comparison operators are refused: `ancestor > 655541` returns Operator '>' is not supported for field 'ancestor'. Supported operators are : =, !=, IN, NOT IN.

## Related

- [parent](https://goingstellar.ro/reference/cql/parent-field/)
- [id](https://goingstellar.ro/reference/cql/id-field/)
- [IN](https://goingstellar.ro/reference/cql/in-operator/)
- [NOT IN](https://goingstellar.ro/reference/cql/not-in-operator/)
- [space](https://goingstellar.ro/reference/cql/space-field/)
- [title](https://goingstellar.ro/reference/cql/title-field/)

## Sources

- [CQL fields (Atlassian Developer, Confluence Cloud)](https://developer.atlassian.com/cloud/confluence/cql-fields/)

