Elasticsearch client with Django support.
Project description
Gum is a Django app for integrate Elasticsearch 1.x with Django.
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
Release history Release notifications | RSS feed
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.0.tar.gz
(10.6 kB
view hashes)
Built Distribution
Close
Hashes for django_gum-1.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3a8ea66d51249b07b88a1cd260dbab26e4edb83bccc14a4b28b31cbae233f94a |
|
MD5 | 62c615d012b404a78a4808e9df3d8f89 |
|
BLAKE2b-256 | 7e04a59d04ab53c3bff3211e742de85ff3e603aa944c6c4b989ac65e25b02141 |