Skip to content

More flexible script query #21479

@nik9000

Description

@nik9000

Now that Kibana supports painless, some strange things have come up around filtering. This is a proposal to implement a thing in Elasticsearch so Kibana doesn't have to do upsetting textual manipulation to user generated script fields.

Background: Kibana lets users configure script fields once and reuse them. The specific usage that is troubling is filtering which Kibana implements by creating a query like this:

                "script" : {
                    "script" : {
                        "inline" : "($scriptText) == params.value",
                        "lang"   : "painless",
                        "params" : {
                            "value" : "whatever the user picked"
                        }
                    }
                }

Specifically, the ($scriptText) == params.value part is scary because script fields that are perfectly valid painless most places are not valid in this script context. Scripts that contain return, ;, or variable declarations are in trouble with a construct like this.

I propose a new version of the script query that'd look like this:

                "script" : {
                    "script" : {
                        "inline"  : $scriptText,
                        "lang"    : "painless",
                        "matches" : "whatever the user picked"
                    }
                }

Instead of casting the return of the script to a boolean we cast it to whatever type is sent in the matches field and then check for equality.

Metadata

Metadata

Assignees

No one assigned

    Labels

    :Core/Infra/ScriptingScripting abstractions, Painless, and Mustache:Search/SearchSearch-related issues that do not fall into other categories>enhancement

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions