Script Fields Usageedit

Fluent DSL Exampleedit

s => s
.ScriptFields(sf => sf
    .ScriptField("test1", sc => sc
        .Inline("doc['my_field_name'].value * 2")
        .Lang("groovy")
    )
    .ScriptField("test2", sc => sc
        .Inline("doc['my_field_name'].value * factor")
        .Lang("groovy")
        .Params(p => p
            .Add("factor", 2.0)
        )
    )
)

Object Initializer Syntax Exampleedit

new SearchRequest<Project>
{
    ScriptFields = new ScriptFields
    {
        { "test1", new ScriptField
        {
            Script = new InlineScript("doc['my_field_name'].value * 2") { Lang = "groovy" }
        } },
        { "test2", new InlineScript("doc['my_field_name'].value * factor")
        {
            Lang = "groovy",
            Params = new FluentDictionary<string, object>
            {
                { "factor", 2.0 }
            }
        } }
    }
}

Example json output. 

{
  "script_fields": {
    "test1": {
      "script": {
        "inline": "doc['my_field_name'].value * 2",
        "lang": "groovy"
      }
    },
    "test2": {
      "script": {
        "inline": "doc['my_field_name'].value * factor",
        "lang": "groovy",
        "params": {
          "factor": 2.0
        }
      }
    }
  }
}