Skip to content

Commit

Permalink
Add django_elasticsearch_dsl
Browse files Browse the repository at this point in the history
  • Loading branch information
jochenklar committed Jun 1, 2022
1 parent 8f59241 commit 9af65d7
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ DATABASE=postgresql://<user>:<pass>@<host>/<db>
# database connection for the django database
DATABASE_METADATA=postgresql://<user>:<pass>@<host>/<db>

# elastic search connection
ELASTICSEARCH_HOST=
ELASTICSEARCH_USE_SSL=
ELASTICSEARCH_CA_CERTS=

# base url for the links to the files
FILES_BASE_URL=http://isimip-files.pik-potsdam.org
FILES_API_URL=http://isimip-files.pik-potsdam.org/api/v1
Expand Down
9 changes: 9 additions & 0 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'rest_framework',
'rest_framework.authtoken',
'django_cleanup',
'django_elasticsearch_dsl',
'django_extensions',
'django_filters',
'adminsortable2',
Expand Down Expand Up @@ -98,6 +99,14 @@
'metadata': dj_database_url.parse(os.getenv('DATABASE_METADATA'))
}

ELASTICSEARCH_DSL = {
'default': {
'hosts': os.getenv('ELASTICSEARCH_HOST', 'localhost:9200'),
'use_ssl': (os.getenv('ELASTICSEARCH_USE_SSL', 'False').upper() == 'TRUE'),
'ca_certs': os.getenv('ELASTICSEARCH_CA_CERTS', False)
},
}

DEFAULT_AUTO_FIELD = 'django.db.models.AutoField'

LANGUAGE_CODE = 'en-us'
Expand Down
21 changes: 21 additions & 0 deletions isimip_data/metadata/documents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from django_elasticsearch_dsl import Document
from django_elasticsearch_dsl.registries import registry
from .models import Dataset


@registry.register_document
class DatasetDocument(Document):
class Index:
name = 'datasets'
settings = {'number_of_shards': 1,
'number_of_replicas': 0}

class Django:
model = Dataset

fields = [
'path'
]

def get_queryset(self):
return Dataset.objects.using('metadata').all()
1 change: 1 addition & 0 deletions requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ Django~=3.2.5
django-admin-sortable2~=1.0.0
django-allauth~=0.45.0
django-cleanup~=5.2.0
django-elasticsearch-dsl~=7.2.2
django-extensions~=3.1.3
django-filter~=2.4.0
django-settings-export~=1.2.1
Expand Down

0 comments on commit 9af65d7

Please sign in to comment.