diff --git a/CHANGELOG.md b/CHANGELOG.md index f097ff1f3b..27e0923576 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,11 @@ Versioning](https://semver.org/spec/v2.0.0.html). - Update frontend overriding system to allow to override any frontend module. +## Added + +- Add settings that permit to configure elastic search client with custom + configuration like custom timeouts. + ## [2.13.0] - 2022-02-18 ### Added diff --git a/sandbox/settings.py b/sandbox/settings.py index b9ee3c5b93..c38f4363b4 100644 --- a/sandbox/settings.py +++ b/sandbox/settings.py @@ -315,6 +315,13 @@ class Base(StyleguideMixin, DRFMixin, RichieCoursesConfigurationMixin, Configura default="richie", environ_name="RICHIE_ES_INDICES_PREFIX", environ_prefix=None ) RICHIE_ES_STATE_WEIGHTS = values.ListValue(None) + # Example to change the timeout: RICHIE_ES_KWARGS={'timeout': 30} + RICHIE_ES_KWARGS = values.DictValue( + {}, environ_name="RICHIE_ES_KWARGS", environ_prefix=None + ) + RICHIE_ES_CREATE_INDEX_KWARGS = values.DictValue( + {}, environ_name="RICHIE_ES_CREATE_INDEX_KWARGS", environ_prefix=None + ) # LTI Content RICHIE_LTI_PROVIDERS = { diff --git a/src/richie/apps/search/__init__.py b/src/richie/apps/search/__init__.py index c0f250adb3..da4f995a80 100644 --- a/src/richie/apps/search/__init__.py +++ b/src/richie/apps/search/__init__.py @@ -10,7 +10,8 @@ default_app_config = "richie.apps.search.apps.SearchConfig" ES_CLIENT = ElasticsearchClientCompat7to6( - [getattr(settings, "RICHIE_ES_HOST", "elasticsearch")] + [getattr(settings, "RICHIE_ES_HOST", "elasticsearch")], + **getattr(settings, "RICHIE_ES_KWARGS", {}), ) ES_INDICES_CLIENT = ElasticsearchIndicesClientCompat7to6(ES_CLIENT) diff --git a/src/richie/apps/search/index_manager.py b/src/richie/apps/search/index_manager.py index 25008e8776..7f3e68a66b 100644 --- a/src/richie/apps/search/index_manager.py +++ b/src/richie/apps/search/index_manager.py @@ -46,7 +46,10 @@ def perform_create_index(indexable, logger=None): # Create the new index if logger: logger.info(f'Creating a new Elasticsearch index "{new_index:s}"...') - ES_INDICES_CLIENT.create(index=new_index) + ES_INDICES_CLIENT.create( + index=new_index, + **getattr(settings, "RICHIE_ES_CREATE_INDEX_KWARGS", {}), + ) # The index needs to be closed before we set an analyzer ES_INDICES_CLIENT.close(index=new_index)