2

I've tried to execute .groovy file from curl command line but failed & received the following error as below. Here is my setup :

elasticsearch.yml

script.inline: true
script.indexed: true

config/scripts/** counterPostCount.groovy**

postCount += 1

Note : basically I want to plus 1 for the value that I already have for 'postCount' field in my document.

document : hashtag

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

1 Answer 1

1

You're almost there, but you have two typos in your query,

  • _script should be `script``
  • script_id is for indexed script (hint: the error mentions that there is no .script index), use file instead for file scripts

It should read like this instead:

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

You don't have to change anything in your elasticsearch.yml file as file scripts are enabled by default

Sign up to request clarification or add additional context in comments.

6 Comments

Thank you Val. I replaced _script and script_id but received the new error as follow : {"error":{"root_cause":[{"type":"remote_transport_exception","reason":"[WinAppNode1][127.0.0.1:9300][indices:data/write/update[s]]"}],"type":"illegal_argument_exception","reason":"failed to execute script","caused_by":{"type":"script_exception","reason":"failed to run file script [counterPostCount] using lang [groovy]","caused_by":{"type":"missing_property_exception","reason":"No such property: postCount for class: a09142c1ac03bff417e4b55d8b280c22540b28b5"}}},"status":400}
There were two changes to make.
Your counterPostCount.groovy script uses the field postCount which doesn't seem to exist.
I do have postCount field in my document under _source. weird. did I miss anything else, Val?
Can you update your question with your actual script and your hashtag mapping?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.