Dynamically adding runtime fields

Dear all,

I have a few runtime fields with painless scripts in my mappings that work pretty well. So far I have a list of all the date fields to index. However, things are changing and now I have the problem that there may be an unknown amount of new date fields. I already have a dynamic mapping which also creates the date fields for me as a date data type. But when it comes to creating runtime fields for the days of the week, I'm at a loss.

An excerpt from my current mapping:

[...]
    "dynamic_templates": [
      {
        "DateValue": {
          "path_match": "*.DateValue",
          "mapping": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss||strict_date_optional_time"
          }
        }
      },
[...]
    "runtime": {
      "Created.DayOfWeek": {
        "type": "keyword",
        "script": {
          "source": "String WeekDay = doc['Created'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT); if ( ! WeekDay.empty ) emit( WeekDay )"
        }
      },
[...]

In my example I have a field that arrives as Created.DateValue and is recognized by the dynamic mapping and stored as a date data type.

Question:

How can I automate the mapping, so that every incoming date filed also gets a relevant XXX.DayOfWeek runtime field?

I was trying to get this done in the dynamic template using the {name} template variable, but without success.

[...]
    "dynamic_templates": [
      {
        "DateValue": {
          "path_match": "*.DateValue",
          "mapping": {
            "type": "date",
            "format": "yyyy-MM-dd HH:mm:ss||strict_date_optional_time",
            "fields": {
              "DayOfWeek": {
                "type": "keyword",
                "script": {
                  "source": "String WeekDay = doc[{name}].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT); if ( ! WeekDay.empty ) emit( WeekDay )"
                }
              }
            }
          }
        }
      },
[...]

-- Cheers, Nils

I suppose the way to use multi-fields in runtime mappings is described here.

I have no idea about how to use runtime fields as sub fields as ordinal multi-fields mappings.

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