id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 28852 Search in admin can't use index when several fields are in `search_fields` Jonathan Sundqvist nobody "There are a couple of issues with the current implementation of search. If you have several fields like the following example. {{{ class MyAdmin(model.ModelAdmin): search_fields = ['=field_1', '@field_2'] }}} You'll never be able to use any of the indexes that may exist on those fields, and if you were to remove `field_1` you would still not be able to use any index on the full text search index for `field_2`. If you have two or more fields in search fields you'll end up with a where statement that uses OR, and the index won't be used. In the case of a full text index you need to define the index with the appropriate config for the ts_vector. (See https://www.postgresql.org/docs/current/static/textsearch-tables.html#TEXTSEARCH-TABLES-INDEX). The current implementation uses `__search` (https://github.com/django/django/blob/master/django/contrib/admin/options.py#L945) which ignores a specific config. So the index won't be used during the query. To accomodate a config for a full text search I would suggest using `@english@field_2`. Then you could split on '@' and use a SearchVector and SearchQuery with the config `english`. To make it possible to use index when several fields are defined in `search_fields`, instead of using OR. Make several querysets and do a union on all them. That way it will execute the query using the index. " Cleanup/optimization closed contrib.admin dev Normal wontfix search Tomer Chachamu Unreviewed 0 0 0 0 0 0