1 <h1>NOTMUCH-SEARCH-TERMS(7)</h1>
5 notmuch-search-terms - syntax for notmuch queries
10 <b>notmuch</b> <b>count</b> [option ...] <<u>search-term</u>> ...
12 <b>notmuch</b> <b>dump</b> [--gzip] [--format=(batch-tag|sup)] [--output=<<u>file</u>>] [--]
13 [<<u>search-term</u>> ...]
15 <b>notmuch</b> <b>reindex</b> [option ...] <<u>search-term</u>> ...
17 <b>notmuch</b> <b>search</b> [option ...] <<u>search-term</u>> ...
19 <b>notmuch</b> <b>show</b> [option ...] <<u>search-term</u>> ...
21 <b>notmuch</b> <b>tag</b> +<<u>tag</u>> ... -<<u>tag</u>> [--] <<u>search-term</u>> ...
26 Several notmuch commands accept a common syntax for search terms.
28 The search terms can consist of free-form text (and quoted phrases)
29 which will match all messages that contain all of the given
30 terms/phrases in the body, the subject, or any of the sender or recipi‐
33 As a special case, a search string consisting of exactly a single as‐
34 terisk ("*") will match all messages.
37 <h3> Search prefixes</h3>
39 In addition to free text, the following prefixes can be used to force
40 terms to match against specific portions of an email, (where <brackets>
41 indicate user-supplied values).
43 Some of the prefixes with <regex> forms can be also used to restrict
44 the results to those whose value matches a regular expression (see
45 <b>regex</b>(7)) delimited with //, for example:
47 notmuch search 'from:"/bob@.*[.]example[.]com/"'
49 <b>body:<word-or-quoted-phrase></b>
50 Match terms in the body of messages.
52 <b>from:<name-or-address></b> <b>or</b> <b>from:/<regex>/</b>
53 The <b>from:</b> prefix is used to match the name or address of the
54 sender of an email message.
56 <b>to:<name-or-address></b>
57 The <b>to:</b> prefix is used to match the names or addresses of any
58 recipient of an email message, (whether To, Cc, or Bcc).
60 <b>subject:<word-or-quoted-phrase></b> <b>or</b> <b>subject:/<regex>/</b>
61 Any term prefixed with <b>subject:</b> will match only text from the
62 subject of an email. Searching for a phrase in the subject is
63 supported by including quotation marks around the phrase, imme‐
64 diately following <b>subject:</b>.
66 <b>attachment:<word></b>
67 The <b>attachment:</b> prefix can be used to search for specific file‐
68 names (or extensions) of attachments to email messages.
70 <b>mimetype:<word></b>
71 The <b>mimetype:</b> prefix will be used to match text from the con‐
72 tent-types of MIME parts within email messages (as specified by
75 <b>tag:<tag></b> <b>or</b> <b>tag:/<regex>/</b> <b>or</b> <b>is:<tag></b> <b>or</b> <b>is:/<regex>/</b>
76 For <b>tag:</b> and <b>is:</b> valid tag values include <b>inbox</b> and <b>unread</b> by
77 default for new messages added by <b>notmuch</b> <b>new</b> as well as any
78 other tag values added manually with <b>notmuch</b> <b>tag</b>.
80 <b>id:<message-id></b> <b>or</b> <b>mid:<message-id></b> <b>or</b> <b>mid:/<regex>/</b>
81 For <b>id:</b> and <b>mid:</b>, message ID values are the literal contents of
82 the Message-ID: header of email messages, but without the '<',
83 '>' delimiters.
85 <b>thread:<thread-id></b>
86 The <b>thread:</b> prefix can be used with the thread ID values that
87 are generated internally by notmuch (and do not appear in email
88 messages). These thread ID values can be seen in the first col‐
89 umn of output from <b>notmuch</b> <b>search</b>
91 <b>thread:{<notmuch</b> <b>query>}</b>
92 Threads may be searched for indirectly by providing an arbitrary
93 notmuch query in <b>{}</b>. For example, the following returns threads
94 containing a message from mallory and one (not necessarily the
95 same message) with Subject containing the word "crypto".
97 % notmuch search 'thread:"{from:mallory}" and thread:"{subject:crypto}"'
99 The performance of such queries can vary wildly. To understand
100 this, the user should think of the query <b>thread:{<something>}</b> as
101 expanding to all of the thread IDs which match <b><something></b>; not‐
102 much then performs a second search using the expanded query.
104 <b>path:<directory-path></b> <b>or</b> <b>path:<directory-path>/**</b> <b>or</b> <b>path:/<regex>/</b>
105 The <b>path:</b> prefix searches for email messages that are in partic‐
106 ular directories within the mail store. The directory must be
107 specified relative to the top-level maildir (and without the
108 leading slash). By default, <b>path:</b> matches messages in the speci‐
109 fied directory only. The "/**" suffix can be used to match mes‐
110 sages in the specified directory and all its subdirectories re‐
111 cursively. <b>path:""</b> matches messages in the root of the mail
112 store and, likewise, <b>path:**</b> matches all messages.
114 <b>path:</b> will find a message if <u>any</u> copy of that message is in the
117 <b>folder:<maildir-folder></b> <b>or</b> <b>folder:/<regex>/</b>
118 The <b>folder:</b> prefix searches for email messages by maildir or MH
119 folder. For MH-style folders, this is equivalent to <b>path:</b>. For
120 maildir, this includes messages in the "new" and "cur" subdirec‐
121 tories. The exact syntax for maildir folders depends on your
122 mail configuration. For maildir++, <b>folder:""</b> matches the inbox
123 folder (which is the root in maildir++), other folder names al‐
124 ways start with ".", and nested folders are separated by "."s,
125 such as <b>folder:.classes.topology</b>. For "file system" maildir, the
126 inbox is typically <b>folder:INBOX</b> and nested folders are separated
127 by slashes, such as <b>folder:classes/topology</b>.
129 <b>folder:</b> will find a message if <u>any</u> copy of that message is in
132 <b>date:<since>..<until></b> <b>or</b> <b>date:<date></b>
133 The <b>date:</b> prefix can be used to restrict the results to only
134 messages within a particular time range (based on the Date:
137 See <b>DATE</b> <b>AND</b> <b>TIME</b> <b>SEARCH</b> below for details on the range expres‐
138 sion, and supported syntax for <since> and <until> date and time
141 The time range can also be specified using timestamps without
142 including the date prefix using a syntax of:
144 <initial-timestamp>..<final-timestamp>
146 Each timestamp is a number representing the number of seconds
147 since 1970-01-01 00:00:00 UTC. Specifying a time range this way
148 is considered legacy and predates the date prefix.
150 <b>lastmod:<initial-revision>..<final-revision></b>
151 The <b>lastmod:</b> prefix can be used to restrict the result by the
152 database revision number of when messages were last modified
153 (tags were added/removed or filenames changed). This is usually
154 used in conjunction with the <b>--uuid</b> argument to <b>notmuch</b> <b>search</b>
155 to find messages that have changed since an earlier query.
157 <b>query:<name></b>
158 The <b>query:</b> prefix allows queries to refer to previously saved
159 queries added with <a href='../notmuch-config-1/'>notmuch-config</a>(1).
161 <b>property:<key>=<value></b>
162 The <b>property:</b> prefix searches for messages with a particular
163 <key>=<value> property pair. Properties are used internally by
164 notmuch (and extensions) to add metadata to messages. A given
165 key can be present on a given message with several different
166 values. See <a href='../notmuch-properties-7/'>notmuch-properties</a>(7) for more details.
168 User defined prefixes are also supported, see <a href='../notmuch-config-1/'>notmuch-config</a>(1) for de‐
172 <h3> Operators</h3>
174 In addition to individual terms, multiple terms can be combined with
175 Boolean operators (<b>and</b>, <b>or</b>, <b>not</b>, and <b>xor</b>). Each term in the query will
176 be implicitly connected by a logical AND if no explicit operator is
177 provided (except that terms with a common prefix will be implicitly
178 combined with OR). The shorthand '-<term>' can be used for 'not
179 <term>' but unfortunately this does not work at the start of an expres‐
180 sion. Parentheses can also be used to control the combination of the
181 Boolean operators, but will have to be protected from interpretation by
182 the shell, (such as by putting quotation marks around any parenthesized
185 In addition to the standard boolean operators, Xapian provides several
186 operators specific to text searching.
188 notmuch search term1 NEAR term2
190 will return results where term1 is within 10 words of term2. The
191 threshold can be set like this:
193 notmuch search term1 NEAR/2 term2
197 notmuch search term1 ADJ term2
199 will return results where term1 is within 10 words of term2, but in the
200 same order as in the query. The threshold can be set the same as with
203 notmuch search term1 ADJ/7 term2
206 <h3> Stemming</h3>
208 <b>Stemming</b> in notmuch means that these searches
210 notmuch search detailed
211 notmuch search details
212 notmuch search detail
214 will all return identical results, because Xapian first "reduces" the
215 term to the common stem (here 'detail') and then performs the search.
217 There are two ways to turn this off: a search for a capitalized word
218 will be performed unstemmed, so that one can search for "John" and not
219 get results for "Johnson"; phrase searches are also unstemmed (see be‐
220 low for details). Stemming is currently only supported for English.
221 Searches for words in other languages will be performed unstemmed.
224 <h3> Wildcards</h3>
226 It is possible to use a trailing '*' as a wildcard. A search for
227 'wildc*' will match 'wildcard', 'wildcat', etc.
230 <h3> Boolean and Probabilistic Prefixes</h3>
232 Xapian (and hence notmuch) prefixes are either <b>boolean</b>, supporting ex‐
233 act matches like "<u>tag:inbox</u>" or <b>probabilistic</b>, supporting a more flexi‐
234 ble <b>term</b> based searching. Certain <b>special</b> prefixes are processed by
235 notmuch in a way not strictly fitting either of Xapian's built in
236 styles. The prefixes currently supported by notmuch are as follows.
239 <b>tag:</b>, <b>id:</b>, <b>thread:</b>, <b>folder:</b>, <b>path:</b>, <b>property:</b>
242 <b>body:</b>, <b>to:</b>, <b>attachment:</b>, <b>mimetype:</b>
245 <b>from:</b>, <b>query:</b>, <b>subject:</b>
248 <h3> Terms and phrases</h3>
250 In general Xapian distinguishes between lists of terms and <b>phrases</b>.
251 Phrases are indicated by double quotes (but beware you probably need to
252 protect those from your shell) and insist that those unstemmed words
253 occur in that order. One useful, but initially surprising feature is
254 that the following are equivalent ways to write the same phrase.
256 • "a list of words"
264 Both parenthesised lists of terms and quoted phrases are ok with proba‐
265 bilistic prefixes such as <b>to:</b>, <b>from:</b>, and <b>subject:</b>. In particular
271 subject:pizza and subject:free
273 Both of these will match a subject "Free Delicious Pizza" while
275 subject:"pizza free"
280 <h3> Quoting</h3>
282 Double quotes are also used by the notmuch query parser to protect
283 boolean terms, regular expressions, or subqueries containing spaces or
284 other special characters, e.g.
286 tag:"a tag"
288 folder:"/^.*/(Junk|Spam)$/"
290 thread:"{from:mallory and date:2009}"
292 As with phrases, you need to protect the double quotes from the shell
295 % notmuch search 'folder:"/^.*/(Junk|Spam)$/"'
296 % notmuch search 'thread:"{from:mallory and date:2009}" and thread:{to:mallory}'
299 <h2>DATE AND TIME SEARCH</h2>
301 notmuch understands a variety of standard and natural ways of express‐
302 ing dates and times, both in absolute terms ("2012-10-24") and in rela‐
303 tive terms ("yesterday"). Any number of relative terms can be combined
304 ("1 hour 25 minutes") and an absolute date/time can be combined with
305 relative terms to further adjust it. A non-exhaustive description of
306 the syntax supported for absolute and relative terms is given below.
309 <h3> The range expression</h3>
311 date:<since>..<until>
313 The above expression restricts the results to only messages from
314 <since> to <until>, based on the Date: header.
316 <since> and <until> can describe imprecise times, such as "yesterday".
317 In this case, <since> is taken as the earliest time it could describe
318 (the beginning of yesterday) and <until> is taken as the latest time it
319 could describe (the end of yesterday). Similarly, date:january..febru‐
320 ary matches from the beginning of January to the end of February.
322 If specifying a time range using timestamps in conjunction with the
323 date prefix, each timestamp must be preceded by @ (ASCII hex 40). As
324 above, each timestamp is a number representing the number of seconds
325 since 1970-01-01 00:00:00 UTC. For example:
326 date:@<initial-timestamp>..@<final-timestamp>
328 Currently, spaces in range expressions are not supported. You can re‐
329 place the spaces with '_', or (in most cases) '-', or (in some cases)
330 leave the spaces out altogether. Examples in this man page use spaces
333 Open-ended ranges are supported. I.e. it's possible to specify
334 date:..<until> or date:<since>.. to not limit the start or end time,
338 <h3> Single expression</h3>
340 date:<expr> works as a shorthand for date:<expr>..<expr>. For example,
341 date:monday matches from the beginning of Monday until the end of Mon‐
345 <h3> Relative date and time</h3>
347 [N|number] (years|months|weeks|days|hours|hrs|minutes|mins|sec‐
350 All refer to past, can be repeated and will be accumulated.
352 Units can be abbreviated to any length, with the otherwise ambiguous
353 single m being m for minutes and M for months.
355 Number can also be written out one, two, ..., ten, dozen, hundred. Ad‐
356 ditionally, the unit may be preceded by "last" or "this" (e.g., "last
357 week" or "this month").
359 When combined with absolute date and time, the relative date and time
360 specification will be relative from the specified absolute date and
363 Examples: 5M2d, two weeks
366 <h3> Supported absolute time formats</h3>
368 • H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]
370 • H[H] (am|a.m.|pm|p.m.)
380 • Examples: 17:05, 5pm
383 <h3> Supported absolute date formats</h3>
397 • D[D][(st|nd|rd|th)] Mon[thname] [YYYY]
399 • Mon[thname] D[D][(st|nd|rd|th)] [YYYY]
403 Month names can be abbreviated at three or more characters.
405 Weekday names can be abbreviated at three or more characters.
407 Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
410 <h3> Time zones</h3>
416 Some time zone codes, e.g. UTC, EET.
421 <a href='../notmuch-1/'>notmuch</a>(1), <a href='../notmuch-config-1/'>notmuch-config</a>(1), <a href='../notmuch-count-1/'>notmuch-count</a>(1), <a href='../notmuch-dump-1/'>notmuch-dump</a>(1), <a href='../notmuch-hooks-5/'>not‐</a>
422 <a href='../notmuch-hooks-5/'>much-hooks</a>(5), <a href='../notmuch-insert-1/'>notmuch-insert</a>(1), <a href='../notmuch-new-1/'>notmuch-new</a>(1), <a href='../notmuch-reindex-1/'>notmuch-reindex</a>(1),
423 <b>notmuch-properties</b>(1), <b>*notmuch-reply</b>(1), <a href='../notmuch-restore-1/'>notmuch-restore</a>(1), <a href='../notmuch-search-1/'>not‐</a>
424 <a href='../notmuch-search-1/'>much-search</a>(1), <b>*notmuch-show</b>(1), <a href='../notmuch-tag-1/'>notmuch-tag</a>(1)
429 Carl Worth and many others
434 2009-2021, Carl Worth and many others