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

标签 elasticsearch groovy

我尝试从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/

    相关文章:

    java - 使用 app.context 时 Grails 重定向到错误的地址?

    elasticsearch - Kibana 将@timestamp 字段显示为可读格式

    grails - Intellij11/Grails 2.0.1编译错误 “BUG! exception in phase '语义分析'”

    elasticsearch - elasticsearch查询中的terms-lookup-filter聚合顺序会影响执行时间(效率)吗?

    twitter - Kibana-显示时间系列的推文-Twitter

    java - 带有 java 和 groovy 源文件夹的 Maven 项目,如何在 POM 中表示

    groovy - Jenkins cps groovy 未捕获 NoSuchMethodError 异常

    groovy - Grails 1.2.x脚本不起作用

    php - Elastic Search/Elasica php-包含NULL的字段的OR查询不起作用

    ElasticSearch:如何在 POST 正文中使用 filter_path 参数