Skip to main content

Search

NetBox v3.4 introduced a new global search mechanism, which employs the extras.CachedValue model to store discrete field values from many models in a single table.

SearchIndex

To enable search support for a model, declare and register a subclass of netbox.search.SearchIndex for it. Typically, this will be done within an app's search.py module.

from netbox.search import SearchIndex, register_search

@register_search
class MyModelIndex(SearchIndex):
model = MyModel
fields = (
('name', 100),
('description', 500),
('comments', 5000),
)
display_attrs = ('site', 'device', 'status', 'description')

A SearchIndex subclass defines both its model and a list of two-tuples specifying which model fields to be indexed and the weight (precedence) associated with each. Guidance on weight assignment for fields is provided below.

Field Weight Guidance

WeightField RoleExamples
50Unique serialized attributeDevice.asset_tag
60Unique serialized attribute (per related object)Device.serial
100Primary human identifierDevice.name, Circuit.cid, Cable.label
110SlugSite.slug
200Secondary identifierProviderAccount.account, DeviceType.part_number
300Highly unique descriptive attributeCircuitTermination.xconnect_id, IPAddress.dns_name
500DescriptionSite.description
1000Custom field default-
2000Other discrete attributeCircuitTermination.port_speed
5000Comment fieldSite.comments