# Script difference between 1.7 and 6.8

**URL:** <https://discuss.elastic.co/t/script-difference-between-1-7-and-6-8/196998>\
**Category:** Elasticsearch\
**Created:** [August 27, 2019, 8:01pm UTC](https://discuss.elastic.co/t/script-difference-between-1-7-and-6-8/196998 "2019-08-27T20:01:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![waldson](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/waldson/32/53103_2.png) [@waldson](https://discuss.elastic.co/u/waldson)\
**Post date:** [August 27, 2019, 8:01pm UTC](https://discuss.elastic.co/t/script-difference-between-1-7-and-6-8/196998/1 "2019-08-27T20:01:38Z")

</div>

Hello,

Does anyone can help on how the following search can be translated to be compatible with ES 6.8?

```auto
GET access-*/_search
{
    "query": {
        "range": {
            "request.time": {
                "gte": "2019-08-21 17:52",
                "lt": "2019-08-21 17:53",
                "format": "yyyy-MM-dd HH:mm"
            }
        }
    },
    "aggs": {
        "group": {
            "terms": {
                "script": "def matcher = doc['request.uri'].value =~ /domain[=\\/]([^\\/=&]+)/; return doc['request.method'].value + '--*' + doc['response.code'].value + '--*' + doc['geoip.country_code2'].value + '--*' + doc['request.uri'].value.split('\\\\?')[0].replaceAll(/\\/(request|domain)\\/[^&\\?\\/]+/, '') + '--*' + (matcher.getCount() > 0 ? matcher[0][1] : '')",
                "size": 10000
            },
            "aggs": {
                "totalResponseTime": {
                    "sum": {
                        "field": "response.time"
                    }
                }
            }
        }
    }
}

```

This is returning the following error:

```auto
#! Deprecation: returning default values for missing document values is deprecated. Set system property '-Des.scripting.exception_for_missing_value=true' to make behaviour compatible with future major versions!
{
  "took" : 17,
  "timed_out" : false,
  "_shards" : {
    "total" : 42,
    "successful" : 39,
    "skipped" : 0,
    "failed" : 3,
    "failures" : [
      {
        "shard" : 0,
        "index" : "access-2019.08.21",
        "node" : "Fy19yOx7SyeH2PKlJCQpPg",
        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            """return doc['request.method'].value + '--*' + doc['response.code'].value + '--*' + doc['geoip.country_code2'].value + '--*' + doc['request.uri'].value.split('\\?')[0].replaceAll(/\/(request|domain)\/[^&\?\/]+/, '') + '--*' + (matcher.getCount() > 0 ? matcher[0][1] : '')""",
            " ^---- HERE"
          ],
          "script" : """def matcher = doc['request.uri'].value =~ /domain[=\/]([^\/=&]+)/; return doc['request.method'].value + '--*' + doc['response.code'].value + '--*' + doc['geoip.country_code2'].value + '--*' + doc['request.uri'].value.split('\\?')[0].replaceAll(/\/(request|domain)\/[^&\?\/]+/, '') + '--*' + (matcher.getCount() > 0 ? matcher[0][1] : '')""",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "dynamic method [java.lang.String, split/1] not found"
          }
        }
      }
    ]
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "group" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : []
    }
  }
}

```

After some research we found out 3 major changes here:

- Split -\> should use like this `/\\?/.split(doc['request.uri'].value)[0]`
- getCount() -\> maybe is not needed anymore
- ReplaceAll -\> similarly to split we should use the pattern and then to the replacement

It ended up like this:

```auto
GET c3532-access-*/_search
{
    "query": {
        "range": {
            "request.time": {
                "gte": "2019-08-21 17:52",
                "lt": "2019-08-21 17:53",
                "format": "yyyy-MM-dd HH:mm"
            }
        }
    },
    "aggs": {
        "group": {
            "terms": {
                "script": "def matches = doc['request.uri'].value =~ /domain[=\\/]([^\\/=&]+)/; return doc['request.method'].value + '--*' + doc['response.code'].value + '--*' + doc['geoip.country_code2'].value + '--*' + /\\/(request|domain)\\/[^&\\?\\/]+/.matcher(/\\\\?/.split(doc['request.uri'].value)[0]).replaceAll('') + '--*' + (matches ? matches[0][1] : '')",
                "size": 10000
            },
            "aggs": {
                "totalResponseTime": {
                    "sum": {
                        "field": "response.time"
                    }
                }
            }
        }
    }
}

```

But now we get the following:

```auto
#! Deprecation: returning default values for missing document values is deprecated. Set system property '-Des.scripting.exception_for_missing_value=true' to make behaviour compatible with future major versions!
{
  "took" : 15,
  "timed_out" : false,
  "_shards" : {
    "total" : 42,
    "successful" : 39,
    "skipped" : 0,
    "failed" : 3,
    "failures" : [
      {
        "shard" : 0,
        "index" : "access-2019.08.21",
        "node" : "Fy19yOx7SyeH2PKlJCQpPg",
        "reason" : {
          "type" : "script_exception",
          "reason" : "runtime error",
          "script_stack" : [
            """return doc['request.method'].value + '--*' + doc['response.code'].value + '--*' + doc['geoip.country_code2'].value + '--*' + /\/(request|domain)\/[^&\?\/]+/.matcher(/\\?/.split(doc['request.uri'].value)[0]).replaceAll('') + '--*' + (matches ? matches[0][1] : '')""",
            " ^---- HERE"
          ],
          "script" : """def matches = doc['request.uri'].value =~ /domain[=\/]([^\/=&]+)/; return doc['request.method'].value + '--*' + doc['response.code'].value + '--*' + doc['geoip.country_code2'].value + '--*' + /\/(request|domain)\/[^&\?\/]+/.matcher(/\\?/.split(doc['request.uri'].value)[0]).replaceAll('') + '--*' + (matches ? matches[0][1] : '')""",
          "lang" : "painless",
          "caused_by" : {
            "type" : "illegal_argument_exception",
            "reason" : "Attempting to address a non-array-like type [java.lang.Boolean] as an array."
          }
        }
      }
    ]
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : []
  },
  "aggregations" : {
    "group" : {
      "doc_count_error_upper_bound" : 0,
      "sum_other_doc_count" : 0,
      "buckets" : []
    }
  }
}

```

And we're stuck on this.

Any help is welcome.

Thanks.

---

<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:** [September 24, 2019, 8:01pm UTC](https://discuss.elastic.co/t/script-difference-between-1-7-and-6-8/196998/2 "2019-09-24T20:01:41Z")

</div>

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