Get AI summaries of any video or article — Sign up free
How to use queries and indentation in Logseq (with examples) thumbnail

How to use queries and indentation in Logseq (with examples)

CombiningMinds·
5 min read

Based on CombiningMinds's video on YouTube. If you like this content, support the original creators by watching, liking and subscribing to their content.

TL;DR

Indentation creates parent/child blocks, and child blocks inherit page links from their parents—this directly shapes query results.

Briefing

Logseq queries become genuinely powerful once indentation is treated as structure: parent blocks define inherited links, child blocks automatically carry those links, and queries then retrieve exactly the blocks that match the inherited page references. The practical payoff is faster, more reliable retrieval than manual filtering—especially when journal entries are nested and scattered across time.

Indentation in Logseq isn’t just formatting. Blocks form a hierarchy where a parent block holds context and child blocks nest under it. Using Tab and Shift+Tab to indent or unindent turns a block into a child of the block above, which means the child inherits backlinks/page links from its parent. This inheritance enables quick collapsing of sections like an outline—chapters under a book, paragraphs under a chapter—while keeping the underlying linked data consistent. The video also distinguishes sibling blocks: blocks at the same indentation level under the same parent don’t inherit each other’s context, which matters when linking and later when queries combine conditions.

Linking is the foundation for queries. Backlinks and hashtags both create links to pages, and the choice is largely personal preference. For multi-word page targets, square brackets (or backlinks) are needed; hashtags work for single-word page names. In practice, the core pattern is: create page links on blocks (either via hashtags or square brackets), then query those page-linked relationships.

To run a query, the forward-slash command “/query” opens the query builder, which uses curly-brace syntax: {query ...}. The simplest form returns all blocks linked to a given page name. Blocks can link directly (a block has the page link itself) or indirectly through inheritance (a child block inherits the page link from its parent). That inheritance is what makes nested journal writing usable for later retrieval.

Queries also support boolean logic, letting users treat sets of blocks like Venn diagrams. Using AND returns blocks that have both page links (e.g., {query [a] [b]} yields the overlap). Using OR returns blocks linked to either page (e.g., {query [a] or [b]} yields the union). A NOT operator enables exclusion, such as “AND a and b but not c,” implemented by nesting {query [a] [b] not [c]}-style logic.

Beyond page links, the query system extends to block types like to-dos and to properties. Properties use a similar bracketed syntax: {query property <name> <value>}, returning pages whose defined property matches. The transcript highlights a “type: books” example, where querying property type=books returns specific book pages. For habit-tracking or quantified-self use cases, properties like wake up and bedtime can be queried to produce a history of values; the results can even be arranged into a markdown table.

Finally, queries are positioned as more than search filters: they provide targeted retrieval that respects parent-block inheritance and can be saved as permanent query pages for quick reuse. The overall message is that indentation plus correct linking turns Logseq into an outline-driven database—one where structured writing and precise querying reinforce each other rather than fighting for attention.

Cornell Notes

Indentation in Logseq creates a parent/child hierarchy where child blocks inherit page links (backlinks/hashtags) from their parents. Queries then use those inherited links to retrieve the right blocks, using curly-brace syntax like {query ...} opened via “/query.” Boolean logic lets users combine link sets: AND returns the overlap of blocks linked to both tags/pages, OR returns the union, and NOT excludes blocks linked to a third page. Queries also extend to block types (like to-dos) and to properties (e.g., property type=books), enabling structured retrieval for workflows like habit tracking. This matters because it makes nested journal writing searchable in a precise, reusable way—often better than manual filtering.

Why does indentation matter for querying in Logseq, beyond visual organization?

Indentation defines parent and child blocks. When a block is indented under another, it becomes a child and inherits the parent’s page links/backlinks. That means a query for a page can return both directly linked blocks and nested child blocks whose links come from inherited context. The transcript also notes sibling blocks: blocks at the same indentation level under the same parent don’t inherit each other’s links, which affects what appears in query results.

How do backlinks and hashtags relate to pages, and what’s the practical difference?

Backlinks and hashtags both create links to pages. The choice is mostly preference, but multi-word page names require square brackets/backlinks rather than plain hashtags. The transcript’s key workflow is: create page links on blocks (via hashtags or square brackets), then query those page-linked relationships to fetch matching blocks later.

What is the basic syntax for a Logseq query that returns blocks linked to a page?

Use “/query” to open the query command, then enter curly-brace syntax: {query <page name(s)>}. If the query is {query page}, it returns blocks linked to the page named “page.” Those blocks may be linked directly (the block has the link) or indirectly via inheritance (the block is a child of a parent block that has the link).

How do AND, OR, and NOT change what a query returns?

The transcript uses Venn-diagram logic. AND returns the overlap—blocks linked to both pages/tags (e.g., {query [a] [b]}). OR returns the union—blocks linked to either page (e.g., {query [a] or [b]}). NOT excludes—blocks that match the included set but do not match the excluded link (e.g., “a and b but not c” implemented by nesting the NOT condition inside the query brackets).

How do properties and to-dos fit into the query system?

Properties can be queried with syntax similar to other query forms, using {query property <name> <value>}. Example: defining type: books on book pages allows a query for property type books to return those pages. For to-dos, the query system supports selecting to-do block types (and also variants like later/doing/done depending on setup), returning blocks that match the specified to-do status/type.

What’s the advantage of queries over manual searching with filters?

Manual filters/search may not fully account for parent-block inheritance, especially when content is written in the journal. Queries are positioned as targeted retrieval that respects the parent/child link inheritance. They also can be saved as permanent query pages, creating a reusable record for frequently needed views.

Review Questions

  1. When a child block inherits links from its parent, how would that affect the results of a {query ...} that targets the parent’s linked page?
  2. Write a boolean query conceptually: which blocks would you expect from an AND query vs an OR query when tags/pages are a, b, and c?
  3. How would you structure properties (like type: books or wake up/bedtime) so that a property query returns the intended set of pages?

Key Points

  1. 1

    Indentation creates parent/child blocks, and child blocks inherit page links from their parents—this directly shapes query results.

  2. 2

    Sibling blocks at the same indentation level do not inherit each other’s links, so query outcomes depend on hierarchy.

  3. 3

    Backlinks and hashtags both create page links; square brackets are needed for multi-word page names.

  4. 4

    Use “/query” to open the query builder and curly-brace syntax like {query ...} to retrieve blocks linked to specific pages.

  5. 5

    Boolean logic in queries works like set operations: AND returns overlap, OR returns union, and NOT excludes a subset.

  6. 6

    Queries can target more than links: they can filter by to-do block types and by properties such as property type=books.

  7. 7

    Queries can be saved as permanent query pages, making repeated retrieval faster and more reliable than manual filtering.

Highlights

Indentation isn’t cosmetic: it turns nested writing into inherited link data that queries can reliably retrieve.
Backlinks and hashtags both link to pages; multi-word targets require square brackets/backlinks rather than plain hashtags.
Boolean query logic maps cleanly to Venn diagrams: AND = overlap, OR = union, NOT = exclusion.
Property queries let structured fields like type=books or wake up/bedtime drive retrieval and even table-style summaries.
Saved queries provide a reusable, targeted alternative to journal searching and filters that may miss inherited context.

Mentioned