首页 文章

Elasticsearch脚本:无法从curl命令行执行.groovy文件

提问于
浏览
2

我试图从curl命令行执行.groovy文件但失败并收到以下错误,如下所示 . 这是我的设置:

elasticsearch.yml

script.inline: true
script.indexed: true

config / scripts / ** counterPostCount.groovy **

postCount += 1

注意:基本上我想在我的文档中为'postCount'字段已经拥有的值加1 .

document : hashtag

{“take”:3,“timed_out”:false,“_ shards”:{“total”:5,“success”:5,“failed”:0},“hits”:{“total”:1,“ max_score“:1.0,”命中“:[{”_ 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 command

curl -XPOST 'http://localhost:9200/hashtag/hashtag/b3ecb430-9fa6-4f41-84da-b79e6a30ef00/_update' -d '{"_script" : {"script_id" : "counterPostCount", "lang" : "groovy"}}'

error

{“error”:{“root_cause”:[{“type”:“remote_transport_exception”,“reason”:“[Node1] [127.0.0.1:9300] [indices:data / write / update [s]]”} ],“type”:“illegal_argument_exception”,“reason”:“执行脚本失败”,“cause_by”:{“type”:“index_not_found_exception”,“reason”:“没有这样的索引”,“resource.type”: “index_expression”, “resource.id”: “脚本”, “指数”: “脚本 ”},“ 状态”:400}

1 回答

  • 1

    你几乎就在那里,但你的查询中有两个拼写错误,

    • _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

相关问题