Python elasticsearch_dsl.Date() Examples

The following are 7 code examples of elasticsearch_dsl.Date(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module elasticsearch_dsl , or try the search function .
Example #1
Source File: elasticsearch.py    From invana-bot with MIT License 6 votes vote down vote up
def get_headers(self, obj):
        """
        this will convert all the headers_Server, headers_Date
        into "header": {
            "Server": "",
            "Date": ""
        }

        :param obj:
        :return:
        """
        headers = {}
        for k, v in obj.items():
            if k.startswith("headers_"):
                headers[k.replace("headers_", "")] = v

        obj['headers'] = headers
        return obj 
Example #2
Source File: mapping.py    From django-seeker with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def document_field(field):
    """
    The default ``field_factory`` method for converting Django field instances to ``elasticsearch_dsl.Field`` instances.
    Auto-created fields (primary keys, for example) and one-to-many fields (reverse FK relationships) are skipped.
    """
    if field.auto_created or field.one_to_many:
        return None
    if field.many_to_many:
        return RawMultiString
    defaults = {
        models.DateField: dsl.Date(),
        models.DateTimeField: dsl.Date(),
        models.IntegerField: dsl.Long(),
        models.PositiveIntegerField: dsl.Long(),
        models.BooleanField: dsl.Boolean(),
        models.NullBooleanField: dsl.Boolean(),
        models.SlugField: dsl.String(index='not_analyzed'),
        models.DecimalField: dsl.Double(),
        models.FloatField: dsl.Float(),
    }
    return defaults.get(field.__class__, RawString) 
Example #3
Source File: reindex_tokens.py    From bearded-avenger with Mozilla Public License 2.0 6 votes vote down vote up
def restore_tokens():
    connections.create_connection(hosts=ES_NODES)
    Index(INDEX_NAME).delete()

    class Token(DocType):
        username = String()
        token = String()
        expires = Date()
        read = Boolean()
        write = Boolean()
        revoked = Boolean()
        acl = String()
        groups = String()
        admin = Boolean()
        last_activity_at = Date()

        class Meta:
            index = INDEX_NAME

    Token.init()
    reindex_results = connections.get_connection().reindex(body={"source": {"index": BACKUP_INDEX_NAME}, "dest": {"index": INDEX_NAME}}, request_timeout=3600)
    if reindex_results.get('created') + reindex_results.get('updated') == reindex_results.get('total'):
        return ('Tokens restored to previous schema successfully!')
    else:
        return ('Tokens did not restore from backup properly') 
Example #4
Source File: elasticsearch.py    From invana-bot with MIT License 5 votes vote down vote up
def setup_collection(self):
        class WebLink(DocType):
            url = Text()
            html = Text()
            headers = Text()
            status = Integer()
            created = Date()

            class Meta:
                index = self.database_name
                doc_type = self.collection_name

        return WebLink 
Example #5
Source File: elasticsearch.py    From invana-bot with MIT License 5 votes vote down vote up
def setup_collection(self):
        class WebLinkExtracted(DocType):
            url = Text()
            body = Text()
            headers = Text()
            status = Integer()
            created = Date()

            class Meta:
                index = self.database_name
                doc_type = self.collection_name

        return WebLinkExtracted 
Example #6
Source File: test_result.py    From elasticsearch-dsl-py with Apache License 2.0 5 votes vote down vote up
def test_bucket_keys_get_deserialized(aggs_data, aggs_search):
    class Commit(Document):
        info = Object(properties={'committed_date': Date()})

        class Index:
            name = 'test-commit'

    aggs_search = aggs_search.doc_type(Commit)
    agg_response = response.Response(aggs_search, aggs_data)

    per_month = agg_response.aggregations.per_month
    for b in per_month:
        assert isinstance(b.key, date) 
Example #7
Source File: test_validation.py    From elasticsearch-dsl-py with Apache License 2.0 5 votes vote down vote up
def test_validation_works_for_lists_of_values():
    class DT(Document):
        i = Date(required=True)

    dt = DT(i=[datetime.now(), 'not date'])
    with raises(ValidationException):
        dt.full_clean()

    dt = DT(i=[datetime.now(), datetime.now()])
    assert None is dt.full_clean()