# Rollup search + script query

**URL:** <https://discuss.elastic.co/t/rollup-search-script-query/172777>\
**Category:** Elasticsearch\
**Created:** [March 18, 2019, 1:07pm UTC](https://discuss.elastic.co/t/rollup-search-script-query/172777 "2019-03-18T13:07:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubarax](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rubarax/32/42238_2.png) [@rubarax](https://discuss.elastic.co/u/rubarax)\
**Post date:** [March 18, 2019, 1:07pm UTC](https://discuss.elastic.co/t/rollup-search-script-query/172777/1 "2019-03-18T13:07:41Z")

</div>

Hello,

I'd like to know if the "script query" can be used with the rollup searchs.

[https://www.elastic.co/guide/en/elasticsearch/reference/6.6/query-dsl-script-query.html#query-dsl-script-query](https://www.elastic.co/guide/en/elasticsearch/reference/6.6/query-dsl-script-query.html#query-dsl-script-query)

I had the following query that works ok using a normal \_search on a normal index:

```
GET index/_search
{
  "size": 0,
  "aggs": {
    "daily": {
      "date_histogram": {
        "field": "timestamp",
        "interval": "24h"
      },
      "aggs": {
        "operations": {
          "terms": {
            "script": {
              "id": "request_operation_types",
              "params": {
                "field": "method"
              }
            }
          }
        }
      }
    }
  }
}

```

But it doesn't work using a \_rollup\_search in a rollup index.

```
GET rollup_index/_rollup_search
{
  "size": 0,
  "aggs": {
    "daily": {
      "date_histogram": {
        "field": "timestamp",
        "interval": "24h"
      },
      "aggs": {
        "operations": {
          "terms": {
            "script": {
              "id": "request_operation_types",
              "params": {
                "field": "method"
              }
            }
          }
        }
      }
    }
  }
}

```

I got

```
{
  "error": {
    "root_cause": [
      {
        "type": "illegal_argument_exception",
        "reason": "There is not a rollup job that has a [terms] agg on field [null] which also satisfies all requirements of query."
      }
    ],
    "type": "illegal_argument_exception",
    "reason": "There is not a rollup job that has a [terms] agg on field [null] which also satisfies all requirements of query."
  },
  "status": 400
}

```

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![polyfractal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/polyfractal/32/48162_2.png) [@polyfractal](https://discuss.elastic.co/u/polyfractal)\
**Post date:** [April 1, 2019, 12:21pm UTC](https://discuss.elastic.co/t/rollup-search-script-query/172777/2 "2019-04-01T12:21:15Z")

</div>

Hmm, looks like a bug. I don't think scripts work well (or at all?) with RollupSearch right now. Internally, Rollup renames all the fields to a very strict convention. Queries are then rewritten to match the field names... but this rewriting process isn't able to rewrite scripts. So scripts are trying to use the old name which doesn't match anymore.

The error itself is because there's a bug in the validation (the terms agg doesn't have a "field" parameter so fails validation)... but the script itself wouldn't work anyway.

I'll see about improving either the error message (failing due to script) or see if maybe we can support scripts.

---

<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:** [April 29, 2019, 12:32pm UTC](https://discuss.elastic.co/t/rollup-search-script-query/172777/3 "2019-04-29T12:32:41Z")

</div>

Closed on April 29, 2019, 12:32pm UTC

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