Constructing a FunctionScoreQuery using NEST

I want to construct a query equivalent to the following JSON

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

However, when I use the following code

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

It gets

{
  "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?

I find out what I want is equivalent to

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

So I use

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.

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