我尝试从curl命令行执行.groovy文件,但失败并收到以下错误,如下所示。这是我的设置:
elasticsearch.yml
script.inline: true
script.indexed: true
config / scripts / ** counterPostCount.groovy **
postCount += 1
注意:基本上,我想为文档中“postCount”字段已经拥有的值加1。
文档:标签
{ "took" : 3, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 1, "max_score" : 1.0, "hits" : [ { "_index" : "hashtag", "_type" : "hashtag", "_id" : "b3ecb430-9fa6-4f41-84da-b79e6a30ef00", "_score" : 1.0, "_source" : { "id" : "b3ecb430-9fa6-4f41-84da-b79e6a30ef00", "hashtagId" : null, "hashtagname" : "helloworld", "dateCreated" : null, "dateUpdated" : null, "postCount" : 2 } } ] } }
curl命令
curl -XPOST 'http://localhost:9200/hashtag/hashtag/b3ecb430-9fa6-4f41-84da-b79e6a30ef00/_update' -d '{"_script" : {"script_id" : "counterPostCount", "lang" : "groovy"}}'
错误
{"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[Node1][127.0.0.1:9300][indices:data/write/update[s]]"}],"type":"illegal_argument_exception","reason":"failed to execute script","caused_by":{"type":"index_not_found_exception","reason":"no such index","resource.type":"index_expression","resource.id":".scripts","index":".scripts"}},"status":400}
最佳答案
您快到了,但是查询中有两个错别字,
_script
应该是`script`` script_id
用于索引脚本(提示:该错误提到没有.script
索引),请使用file
代替文件脚本它应改为:
curl -XPOST 'http://localhost:9200/hashtag/hashtag/b3ecb430-9fa6-4f41-84da-b79e6a30ef00/_update' -d '{
"script" : {
"file" : "test",
"lang" : "groovy"
}
}'
您无需更改
elasticsearch.yml
文件中的任何内容,因为文件脚本为enabled by default
关于elasticsearch - Elasticsearch脚本:无法从curl命令行执行.groovy文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37871973/