I've written a groovy script and tested the update_by_query rest functionality using Sense. Everything works perfectly. Then I wanted to simply take the JSON I use in Sense and port that over just like I do with the other query requests using "setSource". That clearly isn't the same thing for UpdateByQuery requests.
I tried to do what was suggested at Java API corresponding to update_by_query but get a NullPointerException when the transport attempts to find a proxy relating to the update by query action type. Is there some magic I'm supposed to know about to get my ES client transport proxy to know about that action?
I thought maybe it was because the actual plugin wasn't installed in the ES node. Fixed that. Still get NPE.
Basically, I don't see any documentation on how to actually do the equivalent update_by_query REST call using the Java transport and the associated query builder APIs. Any tips? Below is the code I've come up with so far...
//this represents the query part of the update_by_query request. Just looks for a single but unique field
String json = Queries.buildQueryJson(getClass(), UPDATE_TAGS, params);
//my "context" object abstracts away access to the underlying ES transport client so I can mock it up if
//a mock library ever became available
SearchRequestBuilder search = SearchAction.INSTANCE.newRequestBuilder(context.getESClient());
//I read in the referenced post that I should explicitly set the types and index, so I do that here. And
//figured I could go ahead and do what I do in other search queries that work, and just set the JSON source
search.setIndices(index).setTypes(type).setSource(json);
//don't know if this is the right thing to do. But using UpdateByQueryRequestBuilder didn't make a diff
//on whether I get NPE when I execute query
UpdateByQueryRequest request = new UpdateByQueryRequest(search.request());
//parameters for my groovy script
Map<String, Object> scriptParams = new HashMap<>();
DomainTracking domainTracking = new DomainTracking();
domainTracking.setDomainId(domainId);
LabelAndCount tag = new LabelAndCount();
tag.setLabel(label);
tag.setCount(count);
scriptParams.put("template", domainTracking);
scriptParams.put("tag", tag);
//script is a file with params above installed in my config/scripts dir for ES node
request.setScript(new Script("TagItem", ScriptType.FILE, "groovy", scriptParams));
//get NPE when transport attempts to reference a proxy looked up by the UpdateByQueryAction type.
context.getESClient().execute(UpdateByQueryAction.INSTANCE, request).actionGet();