1

I am using Bonsai Elastic Search on Heroku and I have a document as follows:

{
   "_index":"myIndex",
   "_type":"result",
   "_id":"1234_is",
   "_version":1,
   "found":true,
   "_source":{
      "query":"is",
      "pubId":1234,
      "counter":1
   }
}

I'm trying to update the counter like this (as per http://www.elasticsearch.org/guide/en/elasticsearch/reference/0.90/docs-update.html):

curl -XPOST 'http://ELASTICSEARCHINSTANCE:9200/myIndex/result/1234_is/_update' -d '{"script" : "ctx._source.counter+=1"}'

But I'm getting the following error:

{
   "error":"ElasticsearchIllegalArgumentException[failed to execute script]; nested: ExpressionScriptCompilationException[Failed to parse expression: ctx._source.counter+=1]; nested: ParseException[ unexpected character '1' at position (21).]; nested: MismatchedTokenException; ",
   "status":400
}
Rach
  • 43
  • 4

2 Answers2

1

On ES 1.4.4 this is how I got it to work:

  1. Add the following line into the elasticsearch.yml file: script.groovy.sandbox.enabled: true
  2. Restart ES

I then ran the following setup which worked great.

PUT hilden1

PUT hilden1/type1/_mapping
{
  "properties": {
    "title": {
      "type": "string"
    },
    "counter": {
      "type": "integer"
    }
  }
}

POST hilden1/type1/1
{
  "title": "t1",
  "counter": 1
}

POST hilden1/type1/2
{
  "title": "t2",
  "counter": 2
}

GET hilden1/type1/_search
{

}

POST hilden1/type1/1/_update
{
  "script": "ctx._source.counter+=1",
  "lang": "groovy"
}
jhilden
  • 12,207
  • 5
  • 53
  • 76
1

Bonsai founder here.

For safety reasons, Bonsai only supports dynamic scripting with sandboxed languages on their multi-tenant environments. Following CVE-2015-1427, and the release of Elasticsearch 1.4.3 and 1.3.8, Groovy is no longer considered a safe language for sandboxed dynamic scripts in Elasticsearch.

That said, Groovy is perfectly safe on Bonsai's single-tenant clusters, drop us a line at info@bonsai.io to get a quote for that sort of setup.

Nick Zadrozny
  • 7,906
  • 33
  • 38