Skip to main content

Elasticsearch client with Django support.

Project description

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

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": {}
    }
})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-gum-1.1.1.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

django_gum-1.1.1-py2.py3-none-any.whl (14.0 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file django-gum-1.1.1.tar.gz.

File metadata

  • Download URL: django-gum-1.1.1.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for django-gum-1.1.1.tar.gz
Algorithm Hash digest
SHA256 353f66c1a02440a44985f1f614c69d669b7cda2cd08f3925d92c690d384f26f8
MD5 2f8a1147cd80318eae616898596afbdd
BLAKE2b-256 48229277cd2f90f6b5000f5d68096f4620a40d16ffac224fb9721001ee2eced1

See more details on using hashes here.

Provenance

File details

Details for the file django_gum-1.1.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_gum-1.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 6372e61efe950c6ec9023dfecc3f3ef245aacde25f7a1ea51b1f88e68b629b3b
MD5 b0b927d5b5c8af088376e1d2a15f241a
BLAKE2b-256 980a9c01a53d4f7795f0999699c4d9a2a1da0d329007c8cd154199f3abb0f522

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page