Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

global search on custom field #5554

Closed
ecoutinho opened this issue Dec 30, 2020 · 4 comments
Closed

global search on custom field #5554

ecoutinho opened this issue Dec 30, 2020 · 4 comments
Labels
status: duplicate This issue has already been raised

Comments

@ecoutinho
Copy link

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.

@candlerb
Copy link
Contributor

candlerb commented 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
Copy link
Contributor

candlerb commented Jan 4, 2021

Possible duplicate of #1190

@DanSheps
Copy link
Member

DanSheps commented Jan 5, 2021

Duplicate of #1190

@DanSheps DanSheps marked this as a duplicate of #1190 Jan 5, 2021
@DanSheps DanSheps closed this as completed Jan 5, 2021
@DanSheps DanSheps added the status: duplicate This issue has already been raised label Jan 5, 2021
@DanSheps
Copy link
Member

DanSheps commented 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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: duplicate This issue has already been raised
Projects
None yet
Development

No branches or pull requests

3 participants