global search on custom field #4417

Closed
opened 2025-12-29 18:35:48 +01:00 by adam · 4 comments
Owner

Originally created by @ecoutinho on GitHub (Dec 30, 2020).

The global search on all objects is not searching on custom fields' contents.

Environment

  • Python version: 3.6
  • NetBox version: 2.10.2

Steps to Reproduce

  1. Create a text custom field on Devices or Virtual Machine.
  2. Create a new device with some text in that custom field
  3. On the global search at the top, enter that text.

Expected Behavior

Return devices that have that text in the custom field.

Observed Behavior

That device was not returned.

Originally created by @ecoutinho on GitHub (Dec 30, 2020). The global search on all objects is not searching on custom fields' contents. ### Environment * Python version: 3.6 * NetBox version: 2.10.2 ### Steps to Reproduce 1. Create a text custom field on Devices or Virtual Machine. 2. Create a new device with some text in that custom field 3. On the global search at the top, enter that text. <!-- What did you expect to happen? --> ### Expected Behavior Return devices that have that text in the custom field. <!-- What happened instead? --> ### Observed Behavior That device was not returned.
adam added the status: duplicate label 2025-12-29 18:35:48 +01:00
adam closed this issue 2025-12-29 18:35:48 +01:00
Author
Owner

@candlerb commented on GitHub (Jan 4, 2021):

I'd say this is "feature request" rather than "bug". You can already search on individual custom fields by going to the Devices or Virtual Machines pages as appropriate.

To search for CF values, global search would have to add a new condition to every table it checks, something like:

netbox=# select d.id, kv.key, kv.value from dcim_device d, jsonb_each_text(d.custom_field_data) kv where value like '%ba%';
 id |  key  | value
----+-------+--------
  1 | label | foobar
  2 | label | bazqux
(2 rows)

By default this requires a full table scan:

netbox=# explain select d.id, kv.key, kv.value from dcim_device d, jsonb_each_text(d.custom_field_data) kv where value like '%ba%';
                                  QUERY PLAN
-------------------------------------------------------------------------------
 Nested Loop  (cost=0.00..27.28 rows=360 width=68)
   ->  Seq Scan on dcim_device d  (cost=0.00..1.18 rows=18 width=36)
   ->  Function Scan on jsonb_each_text kv  (cost=0.00..1.25 rows=20 width=64)
         Filter: (value ~~ '%ba%'::text)

Hence making this efficient would require some funky indexing, possibly an expression index but I'm not sure how that works when searching multiple values from the same row.

@candlerb commented on GitHub (Jan 4, 2021): I'd say this is "feature request" rather than "bug". You can already search on individual custom fields by going to the Devices or Virtual Machines pages as appropriate. To search for CF values, global search would have to add a new condition to every table it checks, something like: ``` netbox=# select d.id, kv.key, kv.value from dcim_device d, jsonb_each_text(d.custom_field_data) kv where value like '%ba%'; id | key | value ----+-------+-------- 1 | label | foobar 2 | label | bazqux (2 rows) ``` By default this requires a full table scan: ``` netbox=# explain select d.id, kv.key, kv.value from dcim_device d, jsonb_each_text(d.custom_field_data) kv where value like '%ba%'; QUERY PLAN ------------------------------------------------------------------------------- Nested Loop (cost=0.00..27.28 rows=360 width=68) -> Seq Scan on dcim_device d (cost=0.00..1.18 rows=18 width=36) -> Function Scan on jsonb_each_text kv (cost=0.00..1.25 rows=20 width=64) Filter: (value ~~ '%ba%'::text) ``` Hence making this efficient would require some funky [indexing](https://www.postgresql.org/docs/9.6/datatype-json.html#JSON-INDEXING), possibly an [expression index](https://www.postgresql.org/docs/9.6/indexes-expressional.html) but I'm not sure how that works when searching multiple values from the same row.
Author
Owner

@candlerb commented on GitHub (Jan 4, 2021):

Possible duplicate of #1190

@candlerb commented on GitHub (Jan 4, 2021): Possible duplicate of #1190
Author
Owner

@DanSheps commented on GitHub (Jan 5, 2021):

Duplicate of #1190

@DanSheps commented on GitHub (Jan 5, 2021): Duplicate of #1190
Author
Owner

@DanSheps commented on GitHub (Jan 5, 2021):

Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #1190 for further discussion.

@DanSheps commented on GitHub (Jan 5, 2021): Thank you for submitting this issue, however it appears that this topic has already been raised. Please see issue #1190 for further discussion.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#4417