Index Template and Disable Dynamic mapping

Version 2.11.0

I’m trying to set an index_template on our OpenSearch cluster with a set of defined fields that I want indexed but I want any fields that don’t fall into those defined to still be stored in the document, just not indexed.

Here is a sample of the index template that I put in

PUT /_index_template/standardtemplate
{
   "index_patterns":[
      "mypattern*"
   ],
   "priority": 100,
   "template": {
   "settings":{
      "index":{
         "mapping":{
            "total_fields":{
               "limit":"2000"
            }
         }
      }
   },
   "mappings":{
      "dynamic": false,
      "properties":{
           ....
      }
}
}

It was my understanding that setting the “mappings.dynamic” property to false would achieve this but I’ve noticed that it’s not working. Any suggestions?

Thank you!

@couten Could you share an example of the desired output index?

When the “mappings.dynamic” is set to false, all undefined fields will be stored only in the _source.
This is my example.

PUT /_index_template/standardtemplate
{
   "index_patterns":[
      "mypattern*"
   ],
   "priority": 100,
   "template": {
     "settings":{
        "index":{
           "mapping":{
              "total_fields":{
                 "limit":"2000"
              }
           }
        }
     },
     "mappings":{
        "dynamic": false,
        "properties": {
          "first": {
            "type": "text",
            "fields": {
              "keyword":{
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        }
     }
  }
}
POST mypattern1/_doc
{
  "first": "not_first",
  "second": "second"
}

GET mypattern1

{
  "mypattern1": {
    "aliases": {},
    "mappings": {
      "dynamic": "false",
      "properties": {
        "first": {
          "type": "text",
          "fields": {
            "keyword": {
              "type": "keyword",
              "ignore_above": 256
            }
          }
        }
      }
    },
    "settings": {
      "index": {
        "replication": {
          "type": "DOCUMENT"
        },
        "mapping": {
          "total_fields": {
            "limit": "2000"
          }
        },
        "number_of_shards": "1",
        "provided_name": "mypattern1",
        "creation_date": "1708972480456",
        "number_of_replicas": "1",
        "uuid": "Ij961oBrTfie0EkVXg_r4Q",
        "version": {
          "created": "136327827"
        }
      }
    }
  }
}

GET mypattern1/_search

{
  "took": 5,
  "timed_out": false,
  "_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
  },
  "hits": {
    "total": {
      "value": 1,
      "relation": "eq"
    },
    "max_score": 1,
    "hits": [
      {
        "_index": "mypattern1",
        "_id": "tYay5o0BbsIFAQjgmD07",
        "_score": 1,
        "_source": {
          "first": "not_first",
          "second": "second"
        }
      }
    ]
  }
}