Disabling dynamic mapping of an object's fields, while using dynamic templates to copy_to custom fields

I am indexing data (using Elasticsearch 5.2.x) where I don't know in advance the set of all fields in my records. Since the number of fields is unbounded, I want to disable dynamic mapping of those fields. However, I would like to use dynamic templates to selectively index certain fields (via copy_to). It seems as though if I use "enabled": false to ensure that my object isn't dynamically mapped, then the dynamic template doesn't actually work (ie. none of the object's fields get copied into the copy_to field.)

Here is my current mapping:

{
  "dynamic": "strict",
  "dynamic_templates": [
    {
      "row_fts": {
        "match_mapping_type": "string",
        "path_match": "data.*",
        "mapping": { "type": "text", "copy_to": "row_fts" }
      }
    }
  ],
  "properties": {
    "row_id": { "type": "long" },
    "row_type": { "type": "keyword" },
    "row_fts": { "type": "text", "analyzer": "standard" },
    "data": {
      "type": "object",
      "dynamic": true,
      "enabled": false
    }
  }
}

Is there a way to achieve this? Thanks for your help!

1 Like

Well, through some trial and error, I've discovered that the following gets me part of the way there:

{
  "dynamic": "strict",
  "dynamic_templates": [
    {
      "row_fts": {
        "match_mapping_type": "string",
        "path_match": "data.*",
        "mapping": { "type": "text", "copy_to": "row_fts", "index": "no" }
      }
    }
  ],
  "properties": {
    "row_id": { "type": "long" },
    "row_type": { "type": "keyword" },
    "row_fts": { "type": "text", "analyzer": "standard" },
    "data": {
      "dynamic": true,
      "type": "object"
    }
  }
}

While this does update the mapping with each of the string subfields of the data field, it doesn't actually index those subfields.

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.