tron_jones
tron_jones

Reputation: 219

OpenSearch Dynamic Mapping Template

Can somebody point me to examples or correct documentation for dynamic mapping in opensearch. I am trying to translate the mapping from elastic over to OS.

{
  "dynamic_templates": [
    {
      "tags": {
        "mapping": {
          "ignore_above": 512,
          "type": "keyword"
        },
        "match_mapping_type": "string",
        "match": "tag.*"
      }
    },
    {
      "metrics_long": {
        "mapping": {
          "index": false,
          "type": "float"
        },
        "match_mapping_type": "long"
      }
    },
    {
      "metrics_double": {
        "mapping": {
          "index": false,
          "type": "float"
        },
        "match_mapping_type": "double"
      }
    },
    {
      "text_fields": {
        "mapping": {
          "norms": false
        },
        "match": "*"
      }
    }
  ],
  "properties": {
    "fields.connection_state": {
      "type": "keyword"
    },
    "tags.source": {
      "type": "keyword"
    },
    "tags.interface_name": {
      "type": "keyword"
    },
    "tags.neighbor_address": {
      "type": "keyword"
    },
    "fields.af_data/prefixes_accepted": {
      "type": "long"
    },
    "tags.vrf_name": {
      "type": "keyword"
    },
    "fields.af_data/prefixes_advertised": {
      "type": "long"
    }
  }
}

I am trying to get anything that starts with tag.* to be mapped as a keyword. Do I need to move all these under the properties now or what is the correct structure in OS?

Upvotes: 3

Views: 2835

Answers (2)

Farhad Kazemi
Farhad Kazemi

Reputation: 21

I've tested this and it worked fine for me, I used this on my index_templates for opensearch versions 1.3.1 and 2.8...

the first settings section which is "index" is just there to show you where you should put the "mappings" and is completely optional, also you can set priority to whatever number you like

if the syntax looks weird to you be sure to first check how to create index_templates in opensearch

hope it helps...

{
     "index_patterns": [
       "test-dynamictemplates-log-*"
     ],
     "priority": 1000,
     "template": {
         "settings": {
             "index": {
               "number_of_shards": "3",
               "number_of_replicas": "1",
               "plugins": {
                   "index_state_management": {
                      "rollover_alias": "test-dynamictemplates-log-alias"
                   }
               }
             }
         },
         "mappings": {
           "dynamic_templates":[
             {
                 "message_text":{
                   "match_mapping_type":"string",
                   "mapping":{
                       "type":"text",
                       "fields": {
                         "keyword": {
                           "type": "keyword",
                           "ignore_above": 256
                         }
                       }
                   }
                 }
             },
             {
                 "message_object":{
                   "match_mapping_type":"object",
                   "mapping":{
                       "type":"object"
                   }
                 }
             }
           ]
         }
     }
 }

Upvotes: 1

mdl
mdl

Reputation: 11

I've been looking for this also, but as best as I can gather, OpenSearch does not support dynamic mappings like this. I think you have to explicitly define the mappings for each exact field name, which is really unfortunate.

Upvotes: 1

Related Questions