Skip to main content

Django Gum

Gum is a Django app for integrate Elasticsearch 1.x with Django. You can find documentation at https://django-gum.readthedocs.org.

https://badges.gitter.im/marcosgabarda/django-gum.svg https://badge.fury.io/py/django-gum.svg https://img.shields.io/pypi/dm/django-gum.svg Documentation Status https://travis-ci.org/marcosgabarda/django-gum.svg?branch=master https://coveralls.io/repos/github/marcosgabarda/django-gum/badge.svg?branch=master

Quick start

1 Install using pip:

pip install django-gum

2 Add “gum” to your INSTALLED_APPS settings like this:

INSTALLED_APPS += ('gum',)

3 Add Elasticsearch configuration to your settings like this:

GUM_ELASTICSEARCH_URLS = ["http://127.0.0.1:9200/"]
GUM_ELASTICSEARCH_INDEX = ".gum-tests"

List of available configuration variables:

  • GUM_DEBUG (boolean)

  • GUM_USE_CELERY (boolean)

  • GUM_ELASTICSEARCH_URLS (list)

  • GUM_ELASTICSEARCH_INDEX (string)

4 Create an index.py in your app, with a content like this:

from gum.indexer import MappingType, indexer

class PostMappingType(MappingType):

    def document(self, instance):
        tags_text = " ".join(map(lambda x: x.label, instance.tags.all()))
        return {
            "title": instance.title,
            "content": instance.content,
            "text": "{} {} {}".format(instance.title, instance.content, tags_text)
        }

    def mapping(self):
        return {
            "properties": {
                "title": {
                    "type": "string",
                    "store": True,
                },
                "content": {
                    "type": "string",
                    "store": True,
                },
                "text": {
                    "type": "string",
                    "store": True,
                }
            }
        }

indexer.register(Post, PostMappingType)

5 Update Elasticsearch index:

./manage.py gum --update-index

You can specify the models you want to index:

./manage.py gum --update-index blog.Post

Searching

You can perform Elasticsearch searches (accessing search method) using elasticsearch model attribute:

response = Post.elasticsearch.search(body={
    "query": {
        "match_all": {}
    }
})

Release files for django-gum 2.0.2

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

Source distribution (sdist)

Source distribution for django-gum 2.0.2
File Size Uploaded
django-gum-2.0.2.tar.gz 20.6 kB Details

Release files / django-gum-2.0.2.tar.gz

Download URL django-gum-2.0.2.tar.gz
Size 20.6 kB
Tags Source
SHA-256 checksum
How to use checksums
dd54042bbe6fdf43f39478e21f46c2fb15a17e365305f10923b5863fb12eda04
BLAKE2b-256 checksum
How to use checksums
1b695c0ed8603a4b8373060d6ba9007379d2021f1ba83fd1f2e13a4eebe7f4ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

2.0.2 This release

1 release file

2.0.1

1 release file

2.0

1 release file

1.2

1 release file

1.1.1

2 release files

1.1

2 release files

1.0.1

1 release file

1.0

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