WARNING: Version 5.x has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Script Fields Usage
editScript Fields Usage
editAllows to return a script evaluation (based on different fields) for each hit.
Script fields can work on fields that are not stored, and allow to return custom values to be returned (the evaluated value of the script).
Script fields can also access the actual _source
document and extract specific elements to
be returned from it by using params['_source']
.
See the Elasticsearch documentation on script fields for more detail.
Fluent DSL example
edits => 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 example
editnew 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 } } } } }