Cannot execute scripts using [aggs] context

i wanna use aggs and script in es 6.3 like below

GET /trxdetail-sdall/_search?pretty
{
"aggs": {
"distinct_OPPNAME": {
"terms": {
"script":"doc['OPPACC']+' '+doc['OPPNAME']"
}
}
},
"query": {
"terms": {
"OPPACC.keyword": [
"629005281011"
]
}
}
}

but the result is

"caused_by": {
"type": "illegal_argument_exception",
"reason": "cannot execute scripts using [aggs] context",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "cannot execute scripts using [aggs] context"
}

my setting in elasticsearch.yml is

script.allowed_types: inline
script.allowed_contexts: search, update

my question is how to set the config for using script in aggs? or there is no ways in using script for aggs?

Try This

{
  "aggs": {
    "distinct_OPPNAME": {
      "terms": {
        "script": "doc['OPPACC'].value + ' ' + doc['OPPNAME'].value"
      }
    }
  },
  "query": {
    "terms": {
      "OPPACC.keyword": [
        "629005281011"
      ]
    }
  }
}

thanks for reply。 i try it but the same result

"caused_by": {
"type": "illegal_argument_exception",
"reason": "cannot execute scripts using [aggs] context",
"caused_by": {
"type": "illegal_argument_exception",
"reason": "cannot execute scripts using [aggs] context"
}
}

i think mybe it is the setting problem in Elasticsearch.yml?

There should be a full stack trace in your logs. Can you add that here?

Also, you explicitly have only search and update scripts allowed in your elasticsearch.yml. You need to add aggs there if you want to do terms aggregations:

script.allowed_contexts: search, update, aggs

thanks for reply.

my setting is

script.allowed_types: inline
script.allowed_contexts: search,update,aggs

and used the script like below, then success! thanks alot .

GET /trxdetail-sdall/_search?pretty
{
"aggs": {
"distinct_OPPNAME": {
"terms": {
"script": "doc['OPPACC.keyword'].value + ' ' + doc['OPPNAME.keyword'].value"
}
}
},
"query": {
"terms": {
"OPPACC.keyword": [
"629005281011"
]
}
}
}

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