1

我在 Heroku 上使用 Bonsai Elastic Search,我有一个文件如下:

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

我正在尝试像这样更新计数器(根据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"}'

但我收到以下错误:

{
   "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
}
4

2 回答 2

1

在 ES 1.4.4 上,这就是我让它工作的方式:

  1. 将以下行添加到 elasticsearch.yml 文件中:script.groovy.sandbox.enabled: true
  2. 重启 ES

然后我运行了以下设置,效果很好。

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"
}
于 2015-03-03T16:30:14.423 回答
1

盆景创始人在这里。

出于安全原因,Bonsai 仅支持在其多租户环境中使用沙盒语言编写动态脚本。在 CVE-2015-1427 以及Elasticsearch 1.4.3 和 1.3.8的发布之后,Groovy 不再被认为是 Elasticsearch 中沙盒动态脚本的安全语言。

也就是说,Groovy 在 Bonsai 的单租户集群上非常安全,请发送邮件至 info@bonsai.io 以获取此类设置的报价。

于 2015-03-28T18:03:26.603 回答