Repository: inveniosoftware/invenio-rdm-records (language: python)

Issue:
Can we have strict mappings
https://github.com/inveniosoftware/invenio-vocabularies/pull/212/files#r950006755


Test if something like:

```json
{
strict: true,
...
metadata: {},
custom_fields:{
    dynamic: true,
    ...
}
}
```


Discussion / hints:

## Tests

[Source](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html)

- general `dynamic: strict` with inner objects `dynamic: true`. Does not allow for new inner keys (i18n keys and custom fields)
- general `dynamic: false` with inner objects `dynamic: true`. Allows for new inner keys (i18n keys and custom fields). This means that new keys will be stored in the `_source` (in case someone queries ES directly) but they will not be indexed (not searchable). Is not a perfect solution but is better than allowing them at all levels.

Fix patch:
diff --git a/invenio_rdm_records/records/mappings/v7/rdmrecords/drafts/draft-v5.0.0.json b/invenio_rdm_records/records/mappings/v7/rdmrecords/drafts/draft-v5.0.0.json
index 0d51bca5a..f242104f6 100644
--- a/invenio_rdm_records/records/mappings/v7/rdmrecords/drafts/draft-v5.0.0.json
+++ b/invenio_rdm_records/records/mappings/v7/rdmrecords/drafts/draft-v5.0.0.json
@@ -1,5 +1,6 @@
 {
   "mappings": {
+    "dynamic": false,
     "date_detection": false,
     "numeric_detection": false,
     "properties": {
@@ -33,7 +34,8 @@
         }
       },
       "custom_fields": {
-        "type": "object"
+        "type": "object",
+        "dynamic": true
       },
       "parent": {
         "properties": {
diff --git a/invenio_rdm_records/records/mappings/v7/rdmrecords/records/record-v5.0.0.json b/invenio_rdm_records/records/mappings/v7/rdmrecords/records/record-v5.0.0.json
index 0d51bca5a..f242104f6 100644
--- a/invenio_rdm_records/records/mappings/v7/rdmrecords/records/record-v5.0.0.json
+++ b/invenio_rdm_records/records/mappings/v7/rdmrecords/records/record-v5.0.0.json
@@ -1,5 +1,6 @@
 {
   "mappings": {
+    "dynamic": false,
     "date_detection": false,
     "numeric_detection": false,
     "properties": {
@@ -33,7 +34,8 @@
         }
       },
       "custom_fields": {
-        "type": "object"
+        "type": "object",
+        "dynamic": true
       },
       "parent": {
         "properties": {


Test patch:
diff --git a/tests/fixtures/test_cli.py b/tests/fixtures/test_cli.py
index d4181fbb8..a535b62c6 100644
--- a/tests/fixtures/test_cli.py
+++ b/tests/fixtures/test_cli.py
@@ -142,9 +142,10 @@ def test_create_records_custom_fields(app, location, db, es_clear, cli_runner):
         "properties"
     ]["custom_fields"]
     expected_value = {
+        "dynamic": "true",
         "properties": {
             "cern:myfield": {"type": "text", "fields": {"keyword": {"type": "keyword"}}}
-        }
+        },
     }
     assert record_mapping_field == expected_value
     assert draft_mapping_field == expected_value