我在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
}
这里是盆景的创始人。
出于安全考虑,Bonsai只支持在其多租户环境中使用沙盒语言进行动态脚本编写。继CVE-2015-1427以及Elasticsearch 1.4.3和1.3.8的发布之后,Groovy不再被认为是Elasticsearch中沙盒动态脚本的安全语言。
也就是说,Groovy在Bonsai的单租户集群上是完全安全的,请访问info@bonsai.io以获得此类设置的报价。
在ES 1.4.4上,我就是这样让它工作的:
- 在elasticsearch.yml文件中添加以下行:
script.groovy.sandbox.enabled: true
- 重新启动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"
}