67

How can I exclude a given label from a search, effectively finding all the messages that do not have that label applied?

I've searched Google, SuperUser, and Search operators you can use with Gmail, to no avail.

Here are the searches I've tried, none of which work:

  1. !label:work
  2. NOT label:work
  3. not label:work
  4. -label:work

I did some additional testing and believe - searches work however the search will return conversations if at least one message matches the search. In other words, if there is one message in a conversation that lacks the label work then all the messages in the conversation including those labeled work will be returned.

I want my search to only return a conversation if all the messages lack the label.

I tried to work around the issue (per Gianni Di Noia's advice) by creating a filter that matches emails labeled work and applies the label work to the conversation however the filter is never triggered because filters act on incoming messages only based on the properties of the incoming email, not on the conversation to which Gmail assigns that email.

Google also warned me of this when I set up the filter: enter image description here

1
  • Other people might be interested in a cool Gmail search filter I just found: has:nouserlabels. I wanted to find only email messages with no tags.
    – Ryan
    Commented Nov 18 at 17:19

2 Answers 2

73

You can do searches that exclude certain labels. That is, searches like this will do what you expect: (label:MyLabel1 AND NOT label:inbox AND NOT label:MyBadLabel1)

That search will show you only messages that:

  1. Do have MyLabel1
  2. And do not have label inbox
  3. And do not have label MyBadLabel1

The tricks are:

  • to get yourself out of conversation mode! (As @Ruben says above.)
  • to use UPPER CASE for the logic operators (AND NOT will work, and not won't)

If you leave "conversation mode" on, you will get confusing results. For example, doing that search above (with conversation mode on), will likely return messages that do NOT match your search.

It may be a bit weird.

Here's the deal:

  • Conversations are collections of messages that all have the same Subject.
  • When "conversation mode" is on, searches return entire conversations as results.
  • So what should gmail search do if a conversation contains both a message that matches, and a message that does not match your search?
  • You are probably expecting it to return conversations only if all messages in that conversation match.
  • But that is not correct. Instead, Gmail search will return conversations even if only a single message in that conversation matches.
  • So that means that if you do the same search above with "conversation mode" on, the results are likely to include messages that do not match your search!
2
  • Just to further clarify: Using quotes around things like From: names with spaces in them can help get good results: Example: (label:scrum AND NOT from:"Azure DevOps")
    – jaygeek
    Commented Mar 19 at 16:05
  • For those who want to test the assumptions above with conversation mode on: Unlabel all labels of a conversation, then re-apply the same labels. Your search query now works as expected for that conversation. Every email in that conversation is now labeled the same, thus the results are as expected.
    – dimitrieh
    Commented Jun 19 at 17:22
3

As was already explained in the question, filters apply labels to individual incoming messages, so a conversation could have messages with and without the label that the user is looking to exclude from the search results.

To search for individual messages, first turn off the conversation view, then search for the messages without the label.

To search for conversations that don't include any of its messages have certain label, first search for the conversations that include the label and re-apply it, then search for conversations without the corresponding label.

References

0

Not the answer you're looking for? Browse other questions tagged or ask your own question.