2015-03-03 26 views
1

我在Heroku上使用盆景彈性搜索和我有一個文件如下:ElasticsearchIllegalArgumentException時更新腳本

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

回答

1

盆景創始人在這裏。

出於安全原因,盆景只支持在多租戶環境中使用沙盒語言進行動態腳本編寫。按照CVE-2015-1427和Elasticsearch 1.4.3 and 1.3.8的發佈,Groovy不再被認爲是Elasticsearch中的沙盒動態腳本的安全語言。

也就是說,Groovy在盆景的單租戶集羣上是完全安全的,請給我們發郵件[email protected]以獲得此類設置的報價。

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