# Elastic Search | Version 6.7 | NEST | How to Read Script Field Values on Search Result

**URL:** <https://discuss.elastic.co/t/elastic-search-version-6-7-nest-how-to-read-script-field-values-on-search-result/187783>\
**Category:** Elasticsearch\
**Created:** [June 27, 2019, 8:35am UTC](https://discuss.elastic.co/t/elastic-search-version-6-7-nest-how-to-read-script-field-values-on-search-result/187783 "2019-06-27T08:35:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sugumarmani](https://avatars.discourse-cdn.com/v4/letter/s/ecb155/32.png) [@sugumarmani](https://discuss.elastic.co/u/sugumarmani)\
**Post date:** [June 27, 2019, 8:35am UTC](https://discuss.elastic.co/t/elastic-search-version-6-7-nest-how-to-read-script-field-values-on-search-result/187783/1 "2019-06-27T08:35:40Z")

</div>

Hi Guys,  
earlier, I have used elastic 5.7 version in my application for the elastic search feature and used Nest lib in C# to get search results. Recently, upgraded Elastic version to 6.7, similarly, I have updated the relevant C# Code. But, facing issue while reading Script field values and it does not allow me access Value from it.

var remainders = topHits.Hits().Select(x =\> x.Fields).First().ToList();  
var d = ((LazyDocument)remainders[0].Value);

it has field value type as LazyDocument and it does not have the option to read a value from it.

Kindly suggest me any solution to this problem.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [July 1, 2019, 5:06am UTC](https://discuss.elastic.co/t/elastic-search-version-6-7-nest-how-to-read-script-field-values-on-search-result/187783/2 "2019-07-01T05:06:07Z")

</div>

ScriptFields can be accessed as follows

```auto
var client = new ElasticClient();

var searchResponse = client.Search<object>(s => s
    .Source(false)
    .ScriptFields(sf => sf
        .ScriptField("commentMultiplier", sd => sd
            .Source("doc['commentCount'].value * params.factor")
            .Params(d => d
                .Add("factor", 3)
            )
        )
    )
);

// gather a collection of document id and commentMultiplier tuples
var idsAndcommentMultipliers = searchResponse.Hits.Select(h =>
{
    var id = h.Id;
    // Script fields always return an array, so get first value for each document
    var commentMultiplier = h.Fields["commentMultiplier"].As<int[]>().First();  
    return (id, commentMultiplier);
}).ToList();

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 29, 2019, 5:06am UTC](https://discuss.elastic.co/t/elastic-search-version-6-7-nest-how-to-read-script-field-values-on-search-result/187783/3 "2019-07-29T05:06:11Z")

</div>

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