general search: search for Custom field values of the 'selection' type #8519

Closed
opened 2025-12-29 20:37:43 +01:00 by adam · 7 comments
Owner

Originally created by @PurplePetrus on GitHub (Aug 28, 2023).

NetBox version

v3.5.7

Feature type

Change to existing functionality

Proposed functionality

Using the general search, it is currently not possible to search for custom field values of the type 'selection'.
It would be good if we were able to search for this type of values using the general search field as well.

Use case

some custom fields are being used on different types of objects (devices, virtual machines,...). We opted to use the custom field type 'selection' to reduce end user 'fantasy' input.
However, we would like to be able to search for all devices and virtual machines, that have a specific value for that selection field.

Currently searching for the selection field value yields no results. Workaround is currently to search on a per object basis (query in devices, query in virtual machines) using the filters.
This works, but is repetitive and is prone to missing results if not aware in which object types this is used.
The general search box allows us to search in all different types of objects (devices, modules, racks, VM's,...) with only one query.

To reduce the chance on errors in search results and reduce search time for the users, it would be beneficial to 'general search' on custom fields of the type 'selection' as well.

Database changes

none

External dependencies

none

Originally created by @PurplePetrus on GitHub (Aug 28, 2023). ### NetBox version v3.5.7 ### Feature type Change to existing functionality ### Proposed functionality Using the general search, it is currently not possible to search for custom field values of the type 'selection'. It would be good if we were able to search for this type of values using the general search field as well. ### Use case some custom fields are being used on different types of objects (devices, virtual machines,...). We opted to use the custom field type 'selection' to reduce end user 'fantasy' input. However, we would like to be able to search for all devices and virtual machines, that have a specific value for that selection field. Currently searching for the selection field value yields no results. Workaround is currently to search on a per object basis (query in devices, query in virtual machines) using the filters. This works, but is repetitive and is prone to missing results if not aware in which object types this is used. The general search box allows us to search in all different types of objects (devices, modules, racks, VM's,...) with only one query. To reduce the chance on errors in search results and reduce search time for the users, it would be beneficial to 'general search' on custom fields of the type 'selection' as well. ### Database changes none ### External dependencies none
adam added the type: featurepending closure labels 2025-12-29 20:37:43 +01:00
adam closed this issue 2025-12-29 20:37:44 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Aug 28, 2023):

I think this makes sense, not sure if the omission was intentional or just an oversight during the implementation. Perhaps @jeremystretch can shed some light? If it was unintended, we might need to reclassify as a bug.

I tested it out by adding:

CustomFieldTypeChoices.TYPE_SELECT: FieldTypes.STRING,

To:

d79fa131bb/netbox/extras/models/customfields.py (L37-L44)

Seems to work without issue. It's also possible to add the multiple select cf type, however the field value is serialized to for example ['testvalue1', 'testvalue2'] - which works fine for searching, but might look a little odd.

@kkthxbye-code commented on GitHub (Aug 28, 2023): I think this makes sense, not sure if the omission was intentional or just an oversight during the implementation. Perhaps @jeremystretch can shed some light? If it was unintended, we might need to reclassify as a bug. I tested it out by adding: `CustomFieldTypeChoices.TYPE_SELECT: FieldTypes.STRING,` To: https://github.com/netbox-community/netbox/blob/d79fa131bbdaf77014f3ff957db738a49088c447/netbox/extras/models/customfields.py#L37-L44 Seems to work without issue. It's also possible to add the multiple select cf type, however the field value is serialized to for example `['testvalue1', 'testvalue2']` - which works fine for searching, but might look a little odd.
Author
Owner

@jeremystretch commented on GitHub (Aug 28, 2023):

Custom selection values are intentionally excluded from global search because they are not expected to be unique. Much as searching for the string "active" does not return all sites and devices with an "active" status, searching for a custom field selection value does not return all objects with that value. Field-based filters are intended to be used for this purpose instead.

@PurplePetrus you have described the underlying mechanics, but have not provided an actual use. Please revise your post above to provide an example where the proposed functionality would provide value.

@jeremystretch commented on GitHub (Aug 28, 2023): Custom selection values are intentionally excluded from global search because they are not expected to be unique. Much as searching for the string "active" does not return all sites and devices with an "active" status, searching for a custom field selection value does not return all objects with that value. Field-based filters are intended to be used for this purpose instead. @PurplePetrus you have described the underlying mechanics, but have not provided an actual use. Please revise your post above to provide an example where the proposed functionality would provide value.
Author
Owner

@PurplePetrus commented on GitHub (Aug 29, 2023):

my apologies, i'll rephrase the use case.

we added a custom selection fields "Domain","Layer" and "Patch_Group" to devices and virtual machines. Using these fields we can incorporate additional maintenance information on these devices/virtual machines.

Domain:

  • domain 1
  • domain 2

Layer:

  • Frontend
  • Middleware
  • Backend

Patch Group:

  • Group 1
  • Group 2
  • Group 3

We would like to search for all devices and virtual machines that are part of patch_group 'Group 1' in a combined list.
or get a quick overview of these results without having to search each object group (devices, virtual machines) seperatly.

I hope this clarifies the use case.

@PurplePetrus commented on GitHub (Aug 29, 2023): my apologies, i'll rephrase the use case. we added a custom selection fields "Domain","Layer" and "Patch_Group" to devices and virtual machines. Using these fields we can incorporate additional maintenance information on these devices/virtual machines. Domain: - domain 1 - domain 2 Layer: - Frontend - Middleware - Backend Patch Group: - Group 1 - Group 2 - Group 3 We would like to search for all devices and virtual machines that are part of patch_group 'Group 1' in a combined list. or get a quick overview of these results without having to search each object group (devices, virtual machines) seperatly. I hope this clarifies the use case.
Author
Owner

@haristku commented on GitHub (Sep 22, 2023):

I think this makes sense, not sure if the omission was intentional or just an oversight during the implementation. Perhaps @jeremystretch can shed some light? If it was unintended, we might need to reclassify as a bug.

I tested it out by adding:

CustomFieldTypeChoices.TYPE_SELECT: FieldTypes.STRING,

To:

d79fa131bb/netbox/extras/models/customfields.py (L37-L44)

Seems to work without issue. It's also possible to add the multiple select cf type, however the field value is serialized to for example ['testvalue1', 'testvalue2'] - which works fine for searching, but might look a little odd.

is it possible to add additional CustomFieldTypeChoices.TYPE_SELECT: FieldTypes.STRING, with plugin-intercept approach, so we don't have to touch the core code?

@haristku commented on GitHub (Sep 22, 2023): > I think this makes sense, not sure if the omission was intentional or just an oversight during the implementation. Perhaps @jeremystretch can shed some light? If it was unintended, we might need to reclassify as a bug. > > I tested it out by adding: > > `CustomFieldTypeChoices.TYPE_SELECT: FieldTypes.STRING,` > > To: > > https://github.com/netbox-community/netbox/blob/d79fa131bbdaf77014f3ff957db738a49088c447/netbox/extras/models/customfields.py#L37-L44 > > Seems to work without issue. It's also possible to add the multiple select cf type, however the field value is serialized to for example `['testvalue1', 'testvalue2']` - which works fine for searching, but might look a little odd. is it possible to add additional `CustomFieldTypeChoices.TYPE_SELECT: FieldTypes.STRING,` with plugin-intercept approach, so we don't have to touch the core code?
Author
Owner

@DanSheps commented on GitHub (Dec 15, 2023):

I can definitely see both sides of the coin.

On one side, you have the improved efficiency by not indexing a commonly referenced field, but on the other you do lose out on the ability to search those fields.

I will point out, you can generally filter by these custom fields still, even though they are excluded from the search index.

My own use case, I can see where we have a "room type" and it would be nice for non-netbox native users to be able to search for those room types.

@DanSheps commented on GitHub (Dec 15, 2023): I can definitely see both sides of the coin. On one side, you have the improved efficiency by not indexing a commonly referenced field, but on the other you do lose out on the ability to search those fields. I will point out, you can generally filter by these custom fields still, even though they are excluded from the search index. My own use case, I can see where we have a "room type" and it would be nice for non-netbox native users to be able to search for those room types.
Author
Owner

@github-actions[bot] commented on GitHub (Mar 15, 2024):

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. Do not attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our contributing guide.

@github-actions[bot] commented on GitHub (Mar 15, 2024): This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. NetBox is governed by a small group of core maintainers which means not all opened issues may receive direct feedback. **Do not** attempt to circumvent this process by "bumping" the issue; doing so will result in its immediate closure and you may be barred from participating in any future discussions. Please see our [contributing guide](https://github.com/netbox-community/netbox/blob/develop/CONTRIBUTING.md).
Author
Owner

@github-actions[bot] commented on GitHub (May 16, 2024):

This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.

@github-actions[bot] commented on GitHub (May 16, 2024): This issue has been automatically closed due to lack of activity. In an effort to reduce noise, please do not comment any further. Note that the core maintainers may elect to reopen this issue at a later date if deemed necessary.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#8519