# C# NEST: Expression required for "field" specification in FieldValueFactor?

**URL:** <https://discuss.elastic.co/t/c-nest-expression-required-for-field-specification-in-fieldvaluefactor/100803>\
**Category:** Elasticsearch\
**Created:** [September 17, 2017, 7:56pm UTC](https://discuss.elastic.co/t/c-nest-expression-required-for-field-specification-in-fieldvaluefactor/100803 "2017-09-17T19:56:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thomas\_Doman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_doman/32/11409_2.png) [@Thomas\_Doman](https://discuss.elastic.co/u/Thomas_Doman)\
**Post date:** [September 17, 2017, 7:56pm UTC](https://discuss.elastic.co/t/c-nest-expression-required-for-field-specification-in-fieldvaluefactor/100803/1 "2017-09-17T19:56:58Z")

</div>

I'm using NEST and [Elasticsearch.Net](http://Elasticsearch.Net) versions 1.9.2. I'm trying to create a FieldValueFactor scoring function which all seems to work properly except I can't figure out how to specify the field I want to use.

```
.Functions(fsd => fsd.FieldValueFactor(d => d.Field(???).Missing(0)))

```

I'd like to just specify a string literal here of the field I want to use as the value factor field just like I've done when I create the query DSL by hand. However, there isn't an overload for that. The only .Field() API takes:

```
Expression<Func<object, object>>

```

Even if I created an expression tree, what should it look like? All I want to do is indicate that I want, say, the value in the "kumquat" field used as the factor. Again, it's easy to do when crafting the query DSL by hand so I'm confused by this API.

---

<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:** [September 18, 2017, 3:16am UTC](https://discuss.elastic.co/t/c-nest-expression-required-for-field-specification-in-fieldvaluefactor/100803/2 "2017-09-18T03:16:36Z")

</div>

It looks like 1.x client is missing a method that allows a `string` to be passed; 1.x is no longer supported or being actively worked on however.

You can get around this by (ab)using the `.Suffix()` extension method

```
.Functions(fsd => fsd
    .FieldValueFactor(d => d
        .Field(_ => _.Suffix("kumquat"))
        .Missing(0)
    )
)
```

---

<div class="post-metadata">

**Author:** ![Thomas\_Doman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_doman/32/11409_2.png) [@Thomas\_Doman](https://discuss.elastic.co/u/Thomas_Doman)\
**Post date:** [September 18, 2017, 2:24pm UTC](https://discuss.elastic.co/t/c-nest-expression-required-for-field-specification-in-fieldvaluefactor/100803/3 "2017-09-18T14:24:02Z")

</div>

Thank you very much Russ! I will (ab)use the `.Suffix()` extension method. We have our upgrade all mapped out but due to our significant reliance on ES, I estimate the work at a couple of sprints for a couple of engineers so we haven't taken that effort forward yet. I really appreciate your assistance with this workaround, I'm getting the expected query DSL and results now.

---

<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:** [September 19, 2017, 6:56am UTC](https://discuss.elastic.co/t/c-nest-expression-required-for-field-specification-in-fieldvaluefactor/100803/4 "2017-09-19T06:56:46Z")

</div>

Glad it helped you out @Thomas_Doman! As a heads up for the changes in going from NEST 1.x to 5.x, I'd recommend having a read of the following:

- NEST 1.x to 2.x changes

- NEST 2.x to 5.x changes

There are quite a few changes in the API from 1.x to 2.x that not only reflect changes in the Elasticsearch APIs, but also to make the naming of methods and types in the client consistent with Elasticsearch's API e.g. `.Field(...)` instead of `.OnField(...)`. The majority of the changes in 2.x to 5.x reflect changes in the Elasticsearch API.

---

<div class="post-metadata">

**Author:** ![Thomas\_Doman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thomas_doman/32/11409_2.png) [@Thomas\_Doman](https://discuss.elastic.co/u/Thomas_Doman)\
**Post date:** [September 20, 2017, 5:33pm UTC](https://discuss.elastic.co/t/c-nest-expression-required-for-field-specification-in-fieldvaluefactor/100803/5 "2017-09-20T17:33:28Z")

</div>

Fantastic, thanks for the resource pointers, I really appreciate that! Yes, I've run into a few of the API inconsistencies e.g. `.TermsLookup()` and I'm looking forward to getting to upgrade, just not sure when it's going to happen.

---

<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:** [October 18, 2017, 5:33pm UTC](https://discuss.elastic.co/t/c-nest-expression-required-for-field-specification-in-fieldvaluefactor/100803/6 "2017-10-18T17:33:29Z")

</div>

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