Skip to content

RuntimeField's Script is an IStoredScript. How do I pass it a param? #5537

Closed
@dharmaturtle

Description

@dharmaturtle

Given the following doc:

POST my-index/_doc
{
  "@timestamp": "2017-02-03T19:27:20.606Z"
}

This script successfully runs. Note that it takes a params:

GET my-index/_search
{
  "fields": [
    "day_of_week"
  ],
  "runtime_mappings": {
    "day_of_week": {
      "type": "keyword",
      "script": {
        "source": "emit(doc['@timestamp'].value.dayOfWeekEnum.getDisplayName(TextStyle.FULL, Locale.ROOT) + params.foo )",
        "params": {
          "foo": " is a good day."
        }
      }
    }
  }
}

In attempting to convert the above to NEST v7.12.0, I noticed that RuntimeField's Script property is of type IStoredScript. I believe this is incorrect, as IStoredScript does not accept any params.

If instead I am incorrect, please let me know how to fix the following SearchRequest so that it can take a params:

var sr = new SearchRequest() {
  RuntimeFields = new RuntimeFields
  (
    new Dictionary<Field, IRuntimeField>
    {{
      new Field("RevisionId"),
      new RuntimeField() {
        Format = "keyword",
        Script = new PainlessScript("this doesn't take a params"),
        Type = FieldType.Long
      }
    }}
  ),
  Query = new IdsQuery {
    Values = new List<Id> { exampleId },
  }
};

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions