Skip to content

How to use script_fields and script_score in a simple query (search) #744

@Eli-Goldberg

Description

@Eli-Goldberg

I have the following query (below), but I can't figure out how to do that in the JS client.
I couldn't find both script_score (1) inside the query, but also script_fields (2) inside the body.

Is this supported in the client?

GET test-index/_search
{
  "query": {
    "function_score": {
      "query": {
        "range": {
          "value": { "lte": 20 }
        }
      },
      "script_score": { <-- (1)
        "script": { "source": "doc['value'].value < 21 ? 1 : 0" }
      }
    }
  },
  "script_fields": { <-- (2)
    "value_below_21": {
      "script": { "inline": "return doc['value'].value < 21 ? 1 : 0" }
    }
  }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions