# Constructing a FunctionScoreQuery using NEST

**URL:** https://discuss.elastic.co/t/constructing-a-functionscorequery-using-nest/290251
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [November 26, 2021, 8:03am UTC](https://discuss.elastic.co/t/constructing-a-functionscorequery-using-nest/290251 "2021-11-26T08:03:58Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![whisperingchild](https://avatars.discourse-cdn.com/v4/letter/w/df705f/32.png) [@whisperingchild](https://discuss.elastic.co/u/whisperingchild)
#### Post date: [November 26, 2021, 8:03am UTC](https://discuss.elastic.co/t/constructing-a-functionscorequery-using-nest/290251/1 "2021-11-26T08:03:59Z")

</div>

I want to construct a query equivalent to the following JSON

```json
{
  "function_score": {
    "script_score": {
      "script": "doc['some-field'].value"
    }
  }
}

```

However, when I use the following code

```auto
var q = new FunctionScoreQuery
{
    Query = new ScriptScoreQuery
    {
        Script = new InlineScript($"doc['some-field'].value"),
        IsVerbatim = true,
    },
    IsVerbatim = true
};

```

It gets

```json
{
  "function_score": {
    "query": {
      "script_score": {
        "script": "doc['some-field'].value"
      }
    }
  }
}

```

which I post it to an ES instance and it gets error.  
I checked FunctionScoreQuery and find nowhere to put the `ScriptScoreQuery`. So how can I get what I want?

---

<div class="post-metadata">

### Author: ![whisperingchild](https://avatars.discourse-cdn.com/v4/letter/w/df705f/32.png) [@whisperingchild](https://discuss.elastic.co/u/whisperingchild)
#### Post date: [November 26, 2021, 8:54am UTC](https://discuss.elastic.co/t/constructing-a-functionscorequery-using-nest/290251/2 "2021-11-26T08:54:42Z")

</div>

I find out what I want is equivalent to

```json
{
  "function_score": {
    "functions": [
      {
        "script_score": {
          "script": {
            "source": "doc['some-field'].value"
          }
        }
      }
    ]
  }
}

```

So I use

```auto
var q = new FunctionScoreQuery
{
    Functions = new List<IScoreFunction>
    {
        new ScriptScoreFunction
        {
            Script = new InlineScript($"doc['{field.FieldName}'].value"),
        }
    },
}

```

to construct the query and get what I want.

---

<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: [December 24, 2021, 8:54am UTC](https://discuss.elastic.co/t/constructing-a-functionscorequery-using-nest/290251/3 "2021-12-24T08:54:58Z")

</div>

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