1

query :-

POST demo_index/_update_by_query
{
 "query" : {
      "terms" : {
          "_id" :[
                "123"
               ]
             }
},
"script" : {
   "source" : "if (cox._source.time < params.time ) { cox.source.time = 8;}",
   "lang": "painless",
   "params" : {
       "time" : 2,
       "acctId" : "999",
       "hash" : "rqwtqw"
    }
  }
}

Trying to implement this in OpenSearch using Java Client but couldn't figure out how to use Script.Builder for creating script data.

I did find some examples of ElasticSearch but I guess classes are different in OpenSearch so not able to use that same classes

1 Answer 1

0

It is possible using the UpdateByQueryRequest. i.e. :

//loading the script
Map<String,Object> scriptParams = Maps.of("some arg", "some arg value");
Script script = new Script(ScriptType.INLINE, 
Script.DEFAULT_SCRIPT_LANG, "your painless script", scriptParams); //default lang is PAINLESS
QueryBuilder queryBuilder = ... your query ..;
UpdateByQueryRequest updateByQueryRequest = new UpdateByQueryRequest()
            .setQuery(queryBuilder)
            .setScript(script);
//sending the update by query request
osClient.updateByQuery(updateByQueryRequest, RequestOptions.DEFAULT);
Sign up to request clarification or add additional context in comments.

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.