Script Query DSL Question

This isn't any sort of issue so much as it is a request to help me satisfy my own curiosity. :slight_smile:

The DSL for using a script in a query looks like:

{
  "query": {
    "script": {
      "script": {
        "file": "my_scripted_check"
      }
    }
  }
}

My question is why are their two script keys? Are there other keys that can be placed in the upper most script object to alter behaviour? Is this simply a legacy of removed functionality? This doesn't occur with scripted aggregations or scoring, only in queries, and I've not managed to find anything in the current documentation to offer insight as to why it might be this way.

Please help put my brain out of it's misery!

It's a bit of legacy and unfortunate naming. The outer script is the name of the query. The inner script is the parameter to specify the script. If you use the default scripting language with inline scripts, and no parameters, then you can have the value of the key be a string, like this:

{
  "query": {
    "script": {
      "script": "if (some condition) { return true; } else { return false; }"
    }
  }
}

The query could more aptly be named filter_script or script_filter as that is what it is used for (it has no score; it is only used for matching).

Note that it might be possible to rework the parsing of the inner script, to remove the extra layer, but extra care would need to be taken with backcompat. The confusion on naming is especially relevant given the new script score query that is being worked on, which may warrant some cleanup on the filter script query. /cc @mayya

2 Likes

Thanks @rjernst, appreciate you taking the time! :slight_smile:

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