Created
June 29, 2020 01:31
-
-
Save caseydm/f1f332da878019670b12c2178c8534bc to your computer and use it in GitHub Desktop.
Elasticsearch 5 to 6 upgrade
This file contains 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 decimal import Decimal | |
from django_elasticsearch_dsl import DocType, Index, fields | |
from record.templatetags.record_tags import currency | |
from .models import Employee, Jurisdiction | |
# Name of the Elasticsearch index | |
employee = Index('employees') | |
# See Elasticsearch Indices API reference for available settings | |
employee.settings( | |
number_of_shards=1, | |
number_of_replicas=0 | |
) | |
@employee.doc_type | |
class EmployeeDocument(DocType): | |
# jurisdiction foreign key references | |
jurisdiction = fields.NestedField(properties={ | |
'name': fields.StringField(), | |
'slug': fields.StringField(index='not_analyzed'), | |
'kind': fields.StringField(index='not_analyzed') | |
}) | |
django_id = fields.IntegerField(attr='id') | |
# decimal fields | |
base = fields.DoubleField() | |
gross = fields.DoubleField() | |
overtime = fields.DoubleField() | |
benefits = fields.DoubleField() | |
total = fields.DoubleField() | |
other = fields.DoubleField() | |
ual = fields.DoubleField() | |
name = fields.TextField( | |
fields={'keyword': fields.KeywordField()} | |
) | |
title = fields.TextField( | |
fields={'keyword': fields.KeywordField()} | |
) | |
class Meta: | |
model = Employee # The model associated with this DocType | |
related_models = [Jurisdiction] | |
# The fields of the model you want to be indexed in Elasticsearch | |
fields = [ | |
'slug', | |
'year', | |
'rank', | |
'status', | |
'notes' | |
] | |
queryset_pagination = 3000 |
This file contains 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 decimal import Decimal | |
from django_elasticsearch_dsl import Document, Index, fields | |
from django_elasticsearch_dsl.registries import registry | |
from record.templatetags.record_tags import currency | |
from .models import Employee, Jurisdiction | |
@registry.register_document | |
class EmployeeDocument(Document): | |
class Index: | |
# Name of the Elasticsearch index | |
name = 'employees' | |
# See Elasticsearch Indices API reference for available settings | |
settings = {'number_of_shards': 1, | |
'number_of_replicas': 0} | |
# jurisdiction foreign key references | |
jurisdiction = fields.NestedField(properties={ | |
'name': fields.TextField(), | |
'slug': fields.TextField(index='not_analyzed'), | |
'kind': fields.TextField(index='not_analyzed') | |
}) | |
django_id = fields.IntegerField(attr='id') | |
# decimal fields | |
base = fields.DoubleField() | |
gross = fields.DoubleField() | |
overtime = fields.DoubleField() | |
benefits = fields.DoubleField() | |
total = fields.DoubleField() | |
other = fields.DoubleField() | |
ual = fields.DoubleField() | |
name = fields.TextField( | |
fields={'keyword': fields.KeywordField()} | |
) | |
title = fields.TextField( | |
fields={'keyword': fields.KeywordField()} | |
) | |
class Django: | |
model = Employee # The model associated with this DocType | |
related_models = [Jurisdiction] | |
# The fields of the model you want to be indexed in Elasticsearch | |
fields = [ | |
'slug', | |
'year', | |
'rank', | |
'status', | |
'notes' | |
] | |
queryset_pagination = 3000 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment