Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

Wagtailmodelsearch

Temporary fork of django-modelsearch

Build Status License Version Documentation

Django ModelSearch allows you to index Django models and search them using the ORM!

It supports PostgreSQL FTS, SQLite FTS5, MySQL FTS, MariaDB FTS, Elasticsearch (7.x, 8.x, and 9.x), and OpenSearch (2.x and 3.x).

Features:

This has been built into Wagtail CMS since 2014 and extracted into a separate package in March 2025.

Installation

Install with PIP, then add to INSTALLED_APPS in your Django settings:

pip install modelsearch
# settings.py

INSTALLED_APPS = [
    ...
    "modelsearch",
    ...
]

By default, Django ModelSearch will index into the database configured in DATABASES["default"] and use PostgreSQL FTS, MySQL FTS, MariaDB FTS or SQLite FTS, if available.

If you are using PostgreSQL, you must additionally add django.contrib.postgres to your INSTALLED_APPS setting.

You can change the indexing configuration, or add additional backends with the MODELSEARCH_BACKENDS setting. For example, to configure Elasticsearch:

# settings.py

MODELSEARCH_BACKENDS = {
    'default': {
        'BACKEND': 'modelsearch.backends.elasticsearch8',
        'URLS': ['https://localhost:9200'],
        'INDEX_PREFIX': 'modelsearch_',
        'TIMEOUT': 5,
        'OPTIONS': {},
        'INDEX_SETTINGS': {},
    }
}

Indexing

To index a model, add modelsearch.index.Indexed to the model class and define some search_fields:

from modelsearch import index
from modelsearch.queryset import SearchableQuerySetMixin


# This mixin adds a .search() method to the models QuerySet
class SongQuerySet(SearchableQuerySetMixin, models.QuerySet):
    pass


# Create a model that inherits from Indexed
class Song(index.Indexed, models.Model):
    name = models.TextField()
    lyrics = models.TextField()
    release_date = models.DateField()
    artist = models.ForeignKey(Artist, related_name='songs')

    objects = SongQuerySet.as_manager()

    # Define a list of fields to index
    search_fields = [
        # Index text fields for full-text search
        # Boost the important fields
        index.SearchField('name', boost=2.0),
        index.SearchField('lyrics'),

        # Index fields that for filtering
        # These get inserted into Elasticsearch for fast filtering
        index.FilterField('release_date'),
        index.FilterField('artist'),

        # Pull in content from related models too
        index.RelatedFields('artist', [
           index.SearchField('name'),
        ]),
    ]

Then run the django-admin rebuild_modelsearch_index to create the indexes, mappings and insert the data. Signals are then used to keep the index in sync with the database.

Searching

Search by calling .search() on the QuerySet!

Song.objects.search("Flying Whales")

Searches also work when reversing ForeignKeys:

opeth.songs.search("Harvest")

You can use Django's .filter(), .exclude() and .order_by() with search too:

Song.objects.filter(release_date__year__lt=1971).search("Iron Man")

The filters are rewitten into the Elasticsearch query to make it run fast with a lot of data.

Release files for wagtailmodelsearch 1.1b1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for wagtailmodelsearch 1.1b1
File Size Uploaded
wagtailmodelsearch-1.1b1.tar.gz 88.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for wagtailmodelsearch 1.1b1
File Interpreter ABI Platform
wagtailmodelsearch-1.1b1-py3-none-any.whl Python 3 none any Details

Total release size: 196.6 kB

Release files / wagtailmodelsearch-1.1b1.tar.gz

Download URL wagtailmodelsearch-1.1b1.tar.gz
Size 88.1 kB
Tags Source
SHA-256 checksum
How to use checksums
12527a217f1b616e4744898418b82ddd482f39cfe3aebd3645d31ebfacf78639
BLAKE2b-256 checksum
How to use checksums
61671fd7d0a9b3b179eb1e0e810d191199b9586d4a82d66b433fa49cfe057910
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release files / wagtailmodelsearch-1.1b1-py3-none-any.whl

Download URL wagtailmodelsearch-1.1b1-py3-none-any.whl
Size 108.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9568bba85d52d5de11622ba5baa01f3ee6b69548d8937f5088e0b8168cb2a909
BLAKE2b-256 checksum
How to use checksums
cd38aef00bee1766638eec92aa2e918aa9a5d0846e7ada4b0ed69dc787df257b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.1b1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page