NOTE: You are looking at documentation for an older release. 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']
.
Script fields can be accessed on the response using .Fields
, similarly to stored fields.
See the Elasticsearch documentation on script fields for more detail.
Fluent DSL example
edits => s .ScriptFields(sf => sf .ScriptField("test1", sc => sc .Source("doc['my_field_name'].value * 2") ) .ScriptField("test2", sc => sc .Source("doc['my_field_name'].value * params.factor") .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") } }, { "test2", new InlineScript("doc['my_field_name'].value * params.factor") { Params = new FluentDictionary<string, object> { { "factor", 2.0 } } } } } }
Example json output.
{ "script_fields": { "test1": { "script": { "source": "doc['my_field_name'].value * 2" } }, "test2": { "script": { "source": "doc['my_field_name'].value * params.factor", "params": { "factor": 2.0 } } } } }