Queries
A query is a block that shows the blocks or the pages of a search.
Simple queries
{{query (and [[Outliner]] (task TODO DOING))}}
| Form | Finds |
|---|---|
[[page]], #tag | Blocks that link to the page. A child of such a block counts too |
"some text" | Blocks with the text |
(task TODO DOING) | Blocks with one of the task markers |
(priority A B) | Blocks with one of the priorities |
(property key value) | Blocks with the property. With no value: blocks that have the key |
(page name) | The blocks of a page |
(between -7d today) | Blocks of the journals between two days. A day is today, yesterday, tomorrow, -7d, +2w, or [[Nov 27th, 2026]] |
(page-property key value) | Pages with the property |
(page-tags tag) | Pages with the tag in their tags property |
(namespace name) | Pages of the namespace |
(and ...), (or ...), (not ...) | Each, one of, none of |
(sort-by key desc) | Sorts by a property, priority, scheduled, deadline, or journal-day |
(sample 5) | The first 5 results |
Advanced queries
An advanced query is Datalog in EDN, in a #+BEGIN_QUERY block:
#+BEGIN_QUERY
{:title "Tasks of the last 14 days"
:query [:find (pull ?b [*])
:in $ ?start ?today
:where
[?b :block/marker ?m]
[(contains? #{"NOW" "DOING"} ?m)]
[?b :block/page ?p]
[?p :block/journal-day ?d]
[(>= ?d ?start)]
[(<= ?d ?today)]]
:inputs [:14d :today]}
#+END_QUERY
Attributes of a block: :block/content, :block/marker, :block/priority, :block/page, :block/parent, :block/refs, :block/path-refs, :block/properties, :block/uuid, :block/scheduled, :block/deadline, :block/collapsed?.
Attributes of a page: :block/name, :block/original-name, :block/journal?, :block/journal-day, :block/tags, :block/alias, :block/namespace, :block/properties. The :page/ names work too.
Clauses: data patterns, predicates (=, !=, <, >, <=, >=, contains?, clojure.string/includes?, starts-with?, ends-with?, re-find), functions with a result (get, get-else, str, count, +, -), missing?, not, or, and, and rules.
Rules of Logseq: (task ?b #{"TODO"}), (priority ?b #{"A"}), (page-ref ?b "name"), (page ?b "name"), (property ?b :key "value"), (has-property ?b :key), (page-property ?p :key "value"), (page-tags ?p #{"tag"}), (between ?b ?start ?end), (block-content ?b "text"), (namespace ?p "name"). A query can bring its own rules with % in :in.
Inputs: :today, :yesterday, :tomorrow, :current-page, :query-page, :7d or :7d-before, :7d-after, and the same with w, m, and y.
:find can count: (count ?b), (sum ?x), (min ?x), (max ?x), (avg ?x).
Differences from Logseq
:result-transformand:vieware Clojure code in Logseq. Outliner knows asort-byof one attribute or one property, and ignores other code.- A pattern with no page reference and no task marker reads each block of the graph. On a large graph it needs seconds the first time.