Logger.getLogger("test").info("querying " + searchHost + ":" + searchPort
+ " at " + searchIndexName + " with " + basicAuthCredentials);
Settings settings = ImmutableSettings.settingsBuilder()
.put("cluster.name", cluster).build();
Client client = new TransportClient(settings).
addTransportAddress(new InetSocketTransportAddress(searchHost, searchPort));
Settings emptySettings = ImmutableSettings.settingsBuilder().build();
RestController contrl = new RestController(emptySettings);
ReIndexAction action = new ReIndexAction(emptySettings, client, contrl) {
@Override protected MySearchHits callback(MySearchHits hits) {
SimpleList res = new SimpleList(hitsPerPage, hits.totalHits());
for (MySearchHit h : hits.getHits()) {
try {
String str = new String(h.source(), charset);
RewriteSearchHit newHit = new RewriteSearchHit(h.id(), h.parent(), h.version(), str);
String someField = newHit.get("some_field");
if (someField.contains("some content")) {
newHit.put("some_field", "IT WORKS!");
}
res.add(newHit);
} catch (UnsupportedEncodingException ex) {
throw new RuntimeException(ex);
}
}
return res;
}
};
// first query, further scroll-queries in reindex!
SearchRequestBuilder srb = action.createScrollSearch(searchIndexName, searchType, filter,
hitsPerPage, withVersion, keepTimeInMinutes);
SearchResponse sr = srb.execute().actionGet();
MySearchResponse rsp = new MySearchResponseES(client, sr, keepTimeInMinutes);
// now feed and call callback
action.reindex(rsp, newIndexName, newType, withVersion, waitInSeconds);
client.close();
}