This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import datetime | |
| import time | |
| from django.conf import settings | |
| import elasticsearch_dsl as es | |
| from elasticsearch.helpers import bulk | |
| from elasticsearch_dsl.connections import connections | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ES_CONNECTIONS = { | |
| 'default': { | |
| 'hosts': [http://localhost:9200], | |
| } | |
| } | |
| ES_INDEXES = { | |
| 'default': [ | |
| ('users', 'some_app.indexes.Article'), | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from pydoc import locate | |
| from django.conf import settings | |
| from django.core.management.base import BaseCommand | |
| class Command(BaseCommand): | |
| def __init__(self): | |
| super(Command, self).__init__() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_reserved_tickets(self, performance=None): | |
| Offer = apps.get_model('events', 'Offer') | |
| Order = apps.get_model('events', 'Order') | |
| offers = Offer.objects.published().filter( | |
| state=1, | |
| ticket_price=self, | |
| ) | |
| if performance: | |
| offers = offers.filter(performance=performance) | |
| pending_tickets = offers.filter(basket__state=0).distinct() \ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| for offer in basket.offer_set.published().exclude(ticket_price__state=13): | |
| _voucher_ids = list(offer.ticket_price.ticket_vouchers_multiple.all().values_list('id', flat=True)) | |
| if (offer.ticket_price.ticket_voucher and offer.ticket_price.ticket_voucher != ticket_price) or (_voucher_ids and ticket_price.id not in _voucher_ids): | |
| .... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| """ | |
| Assume the structure of the document looks like this | |
| { | |
| "user": { | |
| "first_name": "Foo", | |
| "last_name": "Bar", | |
| "age": "30", | |
| "city": { | |
| "id": 5, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from elasticsearch_dsl import connections, UpdateByQuery | |
| def bulk_update_docs(ids, instance, fields_changed=[]): | |
| """ | |
| Arguments: | |
| ids: {list} -- list of ids of documents we want to update | |
| instance {Model instance} -- The updated user model object | |
| fields_changed {list} -- list of the model fields changed | |
| """ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # an example from elasticsearch-dsl docs | |
| from elasticsearch_dsl import analyzer | |
| html_strip = analyzer('html_strip', | |
| tokenizer="standard", | |
| filter=["standard", "lowercase", "stop", "snowball"], | |
| char_filter=["html_strip"] | |
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from elasticsearch_dsl import FacetedSearch, TermsFacet | |
| class TweetSearch(FacetedSearch): | |
| facets = { | |
| # use bucket aggregations to define facets | |
| 'city': TermsFacet(field='user.city.name'), | |
| } |