# Script Query DSL Question

**URL:** <https://discuss.elastic.co/t/script-query-dsl-question/140176>\
**Category:** Elasticsearch\
**Created:** [July 16, 2018, 3:15pm UTC](https://discuss.elastic.co/t/script-query-dsl-question/140176 "2018-07-16T15:15:25Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![strayerror](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@strayerror](https://discuss.elastic.co/u/strayerror)\
**Post date:** [July 16, 2018, 3:15pm UTC](https://discuss.elastic.co/t/script-query-dsl-question/140176/1 "2018-07-16T15:15:25Z")

</div>

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

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

```auto
{
  "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!

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [July 16, 2018, 6:26pm UTC](https://discuss.elastic.co/t/script-query-dsl-question/140176/2 "2018-07-16T18:26:23Z")

</div>

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:

```auto
{
  "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).

---

<div class="post-metadata">

**Author:** ![rjernst](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rjernst/32/6363_2.png) [@rjernst](https://discuss.elastic.co/u/rjernst)\
**Post date:** [July 16, 2018, 6:35pm UTC](https://discuss.elastic.co/t/script-query-dsl-question/140176/3 "2018-07-16T18:35:32Z")

</div>

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](https://github.com/elastic/elasticsearch/issues/30303) that is being worked on, which may warrant some cleanup on the filter script query. /cc @mayya

---

<div class="post-metadata">

**Author:** ![strayerror](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@strayerror](https://discuss.elastic.co/u/strayerror)\
**Post date:** [July 24, 2018, 8:39am UTC](https://discuss.elastic.co/t/script-query-dsl-question/140176/4 "2018-07-24T08:39:05Z")

</div>

Thanks @rjernst, appreciate you taking the time! 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [August 21, 2018, 8:39am UTC](https://discuss.elastic.co/t/script-query-dsl-question/140176/5 "2018-08-21T08:39:11Z")

</div>

Closed on August 21, 2018, 8:39am UTC

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