Skip to main content

Elasticsearch client with Django support.

Project description

Gum is a Django app for integrate Elasticsearch 1.x with Django.

https://badge.fury.io/py/django-gum.svg

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 elasticseaech 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.0rc1.tar.gz (9.9 kB view details)

Uploaded Source

File details

Details for the file django-gum-1.0rc1.tar.gz.

File metadata

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

File hashes

Hashes for django-gum-1.0rc1.tar.gz
Algorithm Hash digest
SHA256 bb40c9615d225b3a076e2598c951d9a13ce921e127b5f6e047bf1c32ee049542
MD5 8be24bc8fd1e0fbb9f99251ca7ed980f
BLAKE2b-256 ce0840ad8e32e4b6fce786dda7ea9293794ffc84f73be59ff541931336228507

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