Skip to content

Cannot construct a desired FunctionScoreQuery #6060

@whisperingchild

Description

@whisperingchild

NEST/Elasticsearch.Net version:
7.10.0
Elasticsearch version:
7.4.2
.NET runtime version:
5.0
Operating system version:

Description of the problem including expected versus actual behavior:
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?

Steps to reproduce:
1.
2.
3.

Expected behavior
A clear and concise description of what you expected to happen.

Provide ConnectionSettings (if relevant):

Provide DebugInformation (if relevant):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions