0

Updatequery.builder only has withscript(string script) function to send the script source , how to send the script id in case of stored script? . I am using spring data elasticsearch 4.1. Thanks

Edit to show the error with Spring data elasticsearch 4.2.1

Map<String,Object> params = new HashMap<>(); params.put("message","this is a test message to test");

UpdateQuery updateQuery = UpdateQuery.builder(Query.findAll()).withScriptType(ScriptType.STORED) .withScriptName("updateScript01").withParams(params).build(); this.elasticsearchRestTemplate(updateQuery,IndexCoordniates.of("sampleIndex1"));

exception: Caused by: org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: id is missing;2: script or doc is missing; at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:26) at org.elasticsearch.action.update.UpdateRequest.validate(UpdateRequest.java:206)

Stored script in elasticsearch from kibana: POST _scripts/updateScript01 { "script": { "lang": "painless", "source": "ctx._source.message = params.message;" } }

2 Answers 2

1

Support for using stored scripts was added in version 4.2. For usage see Sahil's answer.

Edit:

After looking at your sample code:

You need to use updateByQuery(), not update():

this.elasticsearchOperations.updateByQuery(updateQuery,IndexCoordinates.of("sampleindex1"));

btw: "indexSample1" as you had it is no valid Elasticsearch index name. Capital letters are not allowed in an index name.

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

9 Comments

Instead of script, i am providing script type and script name, but receiving the below error. either script, document or query must be set at org.springframework.data.elasticsearch.core.query.UpdateQuery$Builder.build(UpdateQuery.java:438)
This is the query used which is resulting in error: UpdateQuery.builder("sampleID") .withScriptType(ScriptType.STORED).withScriptName("updatescript01") .withParams(params).build();
do you have a query defined? If not, and you want to run the update on all documents use Query.findAll() as query parameter
I have tried that as well, it is still giving error for id and script fields. Caused by: org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: id is missing;2: script or doc is missing; at org.elasticsearch.action.ValidateActions.addValidationError(ValidateActions.java:26) at org.elasticsearch.action.update.UpdateRequest.validate(UpdateRequest.java:206) Query used : UpdateQuery.builder(Query.findAll()).withScriptType(ScriptType.STORED) .withScriptName("updateScript01").withParams(params).build();
Then please provide a reproducible, compilable and runnable example How to create a Minimal, Complete, and Verifiable example.
|
0

Use the below methods with ScriptType->Stored and name being id.

enter image description here

Comments

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.