Filter issues that have only one specific label and no other labels

Ingela Ahlbäck November 13, 2017

We have several labels on issues in my project.
E.g. A, B, C, D, ...

I want to find the issues that have label A and only label A.
That is, I dont want to find any issues having A + another label. Just the ones with A only.

And I dont want to list all other possible labels and exclude them, as in the following query. ( labels=A and labels not in (B,C,D...) )
This is not a good solution when there are a huge amount of other labels.

 

6 answers

2 votes
Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2017

Off the shelf, you can't do it.

It is possible with code, and I've seen two approaches before

1.  A field that counts labels - your query becomes "labels = A and 'count of labels' = 1"

2.  A JQL function - your query becomes "labels = A and labelCount() = 1"

 

Both of these are really easy to implement if you've got ScriptRunner installed, I've done the field one with my own code and SR, and seen SR create the function as well.

Ingela Ahlbäck November 14, 2017

Thank you for your answer. I have not worked much with JIRA.

Have I understood you correctly that for 1) I have to create an new field. How do I get this new field to count number of lables?

I dont think we have ScriptRunner installed. I will check with the administrators.

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 14, 2017

Correct - a scripted field in scriptrunner can be really simple, I suspect it can be done in one line of code for counting labels.

0 votes
Abdallah AlSurakji March 7, 2023

I came across this thread and eventually came up with another solution for anyone still interested. What I did was create a separate structure (XYZ) that pulls the data I want to filter through. Then I add a Filter by Attribute according to exactly the labels I am interested in. 

Then in the search section, I type in a JQL query issue in structure("XYZ"). Then save and now I have a saved filter showing only the labels I want. This workaround will be useful for people who don't have administrative permissions and cannot create new fields like me. Although I believe this uses the scriptrunner extension.

Lee Cash
Contributor
October 10, 2023

How does one add MULTIPLE labels here? I can only get it to work if I add ONE label to the Value field.

0 votes
latt11b October 16, 2020

I use

labels = LabelA AND !labels = LabelB AND !labels = LabelC AND !labels = LabelD

 

! = NOT

 

For me this returns tickets with labels on LabelA but not LabelC or LabelD

Amna Fayyaz June 20, 2022

Hi,

Whatever I do, the labels don't show any results in the search. What could be the issue.

 

Regards,

Amna

Nic Brough -Adaptavist-
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 20, 2022

That sounds like you have not added the column for labels to the issue navigator output?

0 votes
Александр Мирко
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 15, 2018

Is it possible to do that in cloud jira without functions and additional plugins?

Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 15, 2018

No. Jira does not offer this function out-of-the-box. You should consider using a custom field instead of labels.

Александр Мирко
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 16, 2018

Thx

0 votes
Ingela Ahlbäck November 15, 2017

I am now trying to use:

issueFunction in issueFieldMatch("", "labels", "^A$")

but that doesnt work... Give no matches at all.

If I instead have:

issueFunction in issueFieldMatch("", "labels", "A")

ist find all issues with label A but also the issues with several labels.

0 votes
Steven F Behnke
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 13, 2017

I don't think it's possible to write a query like this out-of-the-box.

Suggest an answer

Log in or Sign up to answer