Get key field mapping of flatten field

Hi,

I have a use case for storing a map of key-value items. The keys are not likely to vary from one document to another, but I do not know them in advance. Therefore I am using dynamic_templates in order to index them. It works well and also allows me to fetch the dynamic field names using the field API.

However I have been reading about 'mapping explosions' and I thought to try a different approach. The alternatives I was considering are 'nested' types and 'flattened' type. While 'nested' works, the doc recommends considering using the flattened type instead for key-value pairs.

Looking into using the flattened type, it seems to serve its purpose. But I could not find a way to get the actual keys that were indexed.

For example:

PUT test
{
  "mappings": {
      "dynamic_templates": [
        {
          "custom_dynamic": {
            "path_match": "custom_dynamic.*",
            "mapping": {
              "type":   "keyword"
            }
          }
        }
      ],
    "properties": {
      "custom_flat": {
        "type": "flattened"
      }
    }
  }
}

PUT test/_doc/111
{
  "custom_flat": {
    "custom1": "some value",
    "custom2": "other value"
  },
  "custom_dynamic": {
    "custom1": "some value",
    "custom2": "other value"
  }
}

GET test/_mapping/field/custom_dynamic.* // this will fetch the fields 'custom1' and 'custom2'
GET test/_mapping/field/custom_flat.* // this fetches nothing

Is there a way to fetch the keys (e.g. 'custom1', 'custom2') when using the flattened type?

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