netbox icon indicating copy to clipboard operation
netbox copied to clipboard

Custom Fields results in main Object search

Open akballow opened this issue 3 years ago • 5 comments

NetBox version

2.9.10

Feature type

Change to existing functionality

Proposed functionality

Right now I add custom fields like Device Owner Email in Devices or IP address Owner Email in IPAM. When you search in the custom field search box specifically it works, but If i wanted to search an email across all objects in the main search bar it does not find the emails in the custom fields. It would be nice to have the option for custom fields to return results from the main object search. It could be a check box to enable it.

Use case

Having common custom fields entries searchable across objects for a single search result instead of having to go into each object to search for it.

Database changes

No response

External dependencies

No response

akballow avatar Mar 17 '21 22:03 akballow

This would be possible to implement in a primitive way by appending Q(custom_field_data__icontains=value) to the queryset for the search() method on custom field model filtersets. However, it would not behave the same as the individual custom field filters, which look at each individual custom field and apply the specified filtering logic (loose versus strict).

For example, suppose you have a custom field which stores phone numbers, which you intend to match only when a complete number matches. Taking the shotgun approach here would mean that objects would match on any matching set of digits, such as an AS number. This will likely result in frequent irrelevant search results, and dilutes the value of the global search function.

The alternative approach would be to retrieve the applicable custom fields for each model, and carefully extend the queryset filter to apply each one as intended, however this would introduce a substantial amount of overhead, especially considering that the global search currently defaults to querying for 19 different models. We might be better off deferring this feature until we can come up with a more robust search solution.

jeremystretch avatar Apr 21 '21 00:04 jeremystretch

Some approaches in https://github.com/netbox-community/netbox/issues/1190#issuecomment-754606462

candlerb avatar May 12 '21 19:05 candlerb

Blocked by #7016

jeremystretch avatar Sep 09 '21 19:09 jeremystretch

@jeremystretch Does #7016 make this issue "obsolete", as in this not being a problem anymore?

About the approach of retrieving the applicable custom fields for each model and extending the query, perhaps that would be easier if the user could choose whether or not a custom field should be "searchable" or not. A "simple" checkbox when configuring/creating a custom field. :)

That way the query could be extended with only those fields and it would be up to the user to choose how much overhead to add to searching. Some fields might be relevant for searching, some might make zero sense to search for. A custom field containing an external reference number would be great to be able to search for in the global search. A field containing the number of network interfaces on a device, maybe doesn't make sense to query in the global search (maybe a bad example...).

emil-nasso avatar Mar 17 '22 13:03 emil-nasso

I have a similar problem. I have a custom field 'administrator' in IPAM -> IP Addresses. If I use the 'all object' search the administrator is not found. If I use the 'quick search' in the IPAM -> IP Addresses page the administrator is also not found. The only way to find the administrator is to go to IPAM -> IP Addresses -> Filters -> Administrator.

I saw that similar problems have been mentioned in #1190. Have there been any updates on solving this issue?

Finding custom fields through the main (all object) search would be very helpful to me. Thank you.

tea-zup avatar Jul 26 '22 12:07 tea-zup

I recently opened #10560 to capture work being done on a new search engine for NetBox v3.4. This FR will likely get wrapped up in that initiative, but I'll keep this issue open for now.

jeremystretch avatar Oct 11 '22 17:10 jeremystretch

Preliminary work for this has been completed in 31c246327, but will be folded into #10560 as mentioned above.

jeremystretch avatar Oct 12 '22 14:10 jeremystretch