How to pass a parameter to a script attached to a runtime field

Hi,

Can anyone help me how to pass a parameter to a script attached to a runtime field? With scripted fields 'params' can be used to get to the parameters passed to the script but for runtime fields this does not seem to work. If possible an example in java code would be great!

Thanks

Can you share, what you tried and what version you are on, this snippet seems to work for me on 8.1:

GET my-index-000001/_search
{
  "runtime_mappings": {
    "day_of_week": {
      "type": "keyword",
      "script": {
        "source": "emit(doc[params.field].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT))",
        "params": {
          "field":"@timestamp"
        }
      }
    }
  },
  "aggs": {
    "day_of_week": {
      "terms": {
        "field": "day_of_week"
      }
    }
  }
}

Yes indeed I meanwhile figured that out also. Thanks anyway!

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