Search for multiple tags in url #2096

Closed
opened 2025-12-29 17:22:14 +01:00 by adam · 7 comments
Owner

Originally created by @ossark on GitHub (Nov 7, 2018).

Environment

  • Python version: 2.7.10
  • NetBox version: 2.4.4

Proposed Functionality

It would be nice to be able to search for multiple tags (or other keywords) like so:
https://netbox/api/ipam/prefixes/?tag=vpn1&tag=vpn2

This should yield a list of items that matches both tags. Currently the above URL only returns the items that match tag"vpn2".

Use Case

If one has multiple customers and wants a list of resources that affects a few specific customers this could come in handy. Also, if you want to highlight prefixes that are link nets between sites, tags are appropriate to find the link nets that span over two (or more) specific sites.

Database Changes

External Dependencies

Originally created by @ossark on GitHub (Nov 7, 2018). <!-- NOTE: This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 2.7.10 * NetBox version: 2.4.4 <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality It would be nice to be able to search for multiple tags (or other keywords) like so: https://netbox/api/ipam/prefixes/?tag=vpn1&tag=vpn2 This should yield a list of items that matches both tags. Currently the above URL only returns the items that match tag"vpn2". <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case If one has multiple customers and wants a list of resources that affects a few specific customers this could come in handy. Also, if you want to highlight prefixes that are link nets between sites, tags are appropriate to find the link nets that span over two (or more) specific sites. <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies
adam added the type: bugstatus: accepted labels 2025-12-29 17:22:14 +01:00
adam closed this issue 2025-12-29 17:22:15 +01:00
Author
Owner

@jeremystretch commented on GitHub (Nov 7, 2018):

I'm marking this as a bug (as opposed to a feature request) as I think it's reasonable to expect that tags should work this way already.

As for the implementation, there's some discussion around different approaches here, but we'll probably just make a custom TagFilter() to be reused across all models.

@jeremystretch commented on GitHub (Nov 7, 2018): I'm marking this as a bug (as opposed to a feature request) as I think it's reasonable to _expect_ that tags should work this way already. As for the implementation, there's some discussion around different approaches [here](https://github.com/carltongibson/django-filter/issues/137), but we'll probably just make a custom `TagFilter()` to be reused across all models.
Author
Owner

@ossark commented on GitHub (Nov 8, 2018):

If one would like it to be OR instead of AND. How would that me modelled? I am also seeing a case where you would want to list the items that match tag "vpn1" OR "vpn2" in a single call. I prefer the AND notation though. Not sure what is customary in REST.

@ossark commented on GitHub (Nov 8, 2018): If one would like it to be OR instead of AND. How would that me modelled? I am also seeing a case where you would want to list the items that match tag "vpn1" OR "vpn2" in a single call. I prefer the AND notation though. Not sure what is customary in REST.
Author
Owner

@jeremystretch commented on GitHub (Nov 8, 2018):

The behavior exhibited by existing filters is OR. For example, /devices/?site=foo&site=bar will return devices from either site. (The problem with the tag filter is that only the last tag specified in a list is being considered.)

I don't think there's any inherent mechanism for implying OR vs AND in django-filter.

@jeremystretch commented on GitHub (Nov 8, 2018): The behavior exhibited by existing filters is OR. For example, `/devices/?site=foo&site=bar` will return devices from either site. (The problem with the `tag` filter is that only the last tag specified in a list is being considered.) I don't think there's any inherent mechanism for implying OR vs AND in [django-filter](https://django-filter.readthedocs.io/en/master/).
Author
Owner

@ossark commented on GitHub (Nov 8, 2018):

I understand. What I would prefer for the "?tag=" filter is AND.

What about using the ?tag=vpn1,vpn2 construct to indicate AND?

@ossark commented on GitHub (Nov 8, 2018): I understand. What I would prefer for the "?tag=" filter is AND. What about using the ?tag=vpn1,vpn2 construct to indicate AND?
Author
Owner

@jeremystretch commented on GitHub (Nov 12, 2018):

I've implemented this with the AND logic, such that ?tag=foo&tag=bar will return only objects with both tags assigned.

@jeremystretch commented on GitHub (Nov 12, 2018): I've implemented this with the AND logic, such that `?tag=foo&tag=bar` will return only objects with both tags assigned.
Author
Owner

@alimoghrabi commented on GitHub (Apr 11, 2019):

Is this functionality working properly? I have tested it in my environment and it doesn't seem to be returning the correct data.

@alimoghrabi commented on GitHub (Apr 11, 2019): Is this functionality working properly? I have tested it in my environment and it doesn't seem to be returning the correct data.
Author
Owner

@ossark commented on GitHub (Apr 24, 2019):

Works for me as specified. Are you running a proper version?

On Thu, Apr 11, 2019 at 5:35 PM alimoghrabi notifications@github.com
wrote:

Is this functionality working properly? I have tested it in my environment
and it doesn't seem to be returning the correct data.


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
https://github.com/digitalocean/netbox/issues/2558#issuecomment-482165457,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AND2a1uEfQTVJt7dwvC980bX6iZn0UPNks5vf1ZZgaJpZM4YSIqz
.

@ossark commented on GitHub (Apr 24, 2019): Works for me as specified. Are you running a proper version? On Thu, Apr 11, 2019 at 5:35 PM alimoghrabi <notifications@github.com> wrote: > Is this functionality working properly? I have tested it in my environment > and it doesn't seem to be returning the correct data. > > — > You are receiving this because you authored the thread. > Reply to this email directly, view it on GitHub > <https://github.com/digitalocean/netbox/issues/2558#issuecomment-482165457>, > or mute the thread > <https://github.com/notifications/unsubscribe-auth/AND2a1uEfQTVJt7dwvC980bX6iZn0UPNks5vf1ZZgaJpZM4YSIqz> > . >
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2096